The vast majority of candidates that I am speaking with are struggling to get multiple interviews booked in. In this market, it goes without saying that preparation is key to success. Here's 50 interview questions (from beginner to more advanced) that you may encounter when being interviewed for a TypeScript position: #typescript #interview #recruitment #hiring Uneek Global https://lnkd.in/enKjz-zz
Lewis Rosi’s Post
More Relevant Posts
-
#Success Memory Usage: 76.5 MB, less than 79.33% of Java online submissions for Step-By-Step Directions From a Binary Tree Node to Another. class Solution { List<Character> start; List<Character> destination; boolean dfs(TreeNode root, int value, String curList, boolean isLeft, boolean isRight){ if (root == null) return false; if (curList.equals("start")) { if (isLeft) start.add('1'); else if (isRight) start.add('2'); else start.add('0'); } else{ if (isLeft) destination.add('1'); else if (isRight) destination.add('2'); else destination.add('0'); } if (root.val == value) return true; boolean answer1 = dfs(root.left, value, curList, true, false); if (answer1) return true; boolean answer2 = dfs(root.right, value, curList, false, true); if (answer2) return true; if (curList.equals("start")) start.remove(start.size()-1); else destination.remove(destination.size()-1); return (answer1 | answer2); } public String getDirections(TreeNode root, int startValue, int destValue) { //1.In case the start and dest follow the same path and dest covers greater path then //we start from the (nearest ancestor + 1) //2.In all other cases we do Up steps from start node until we reach the nearest common ancestor and from the nearest common ancestor we traverse the path until we conclude to the dest node String answer = ""; start = new ArrayList<>(); destination = new ArrayList<>(); dfs(root, startValue, "start", false, false); //System.out.println(start); dfs(root, destValue, "dest", false, false); //System.out.println(destination); int lastCommonIndex = 0; //find the nearest common ancestor for (int i=1;i<Math.min(start.size(), destination.size());i++){ if (start.get(i) == destination.get(i)) lastCommonIndex = i; else break; } answer += "U".repeat(start.size()-1-lastCommonIndex); for (int i=lastCommonIndex+1;i<destination.size();i++){ if (destination.get(i) == '1') answer += 'L'; else answer += 'R'; } return answer; } } You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the destination node t. Find the shortest path starting from node s and ending at node t. Generate step-by-step directions of such path as a string consisting of only the uppercase letters 'L', 'R', and 'U'. Each letter indicates a specific direction: 'L' means to go from a node to its left child node 'R' means to go from a node to its right child node 'U' means to go from a node to its parent node Return the shortest path from node s to d
Step-By-Step Directions From a Binary Tree Node to Another - LeetCode
leetcode.com
To view or add a comment, sign in
-
We need to extract each decimal digit from the given number and place it in the reversed number, while ensuring that the result does not exceed the bounds of a 32-bit integer.Initialization: Initialize a variable reverse to store the reversed number and a variable temp to store the remainder of x when divided by 10. Reverse Calculation: Enter a while loop that continues as long as x is not equal to 0. In each iteration: Calculate the last digit of x by taking the remainder when x is divided by 10 (temp = x % 10). Update reverse by multiplying it by 10 and adding temp (reverse = reverse * 10 + temp). Update x by dividing it by 10 to remove the last digit (x = x / 10). Overflow Check: Inside the loop, check if reverse exceeds the bounds of a 32-bit signed integer (Integer.MAX_VALUE and Integer.MIN_VALUE). If it does, return 0 to indicate an overflow condition. Return Reversed Number: Once the loop finishes, return the reversed number reverse as an integer. Check out my solution here. hashtag #LeetCode hashtag #Java hashtag #Coding hashtag #ProblemSolving hashtag #ContinuousLearning hashtag #wearehiring hashtag #hiring hashtag #recruitment hashtag #SoftwareDevelopment hashtag #Technology hashtag #Algorithm hashtag #ArtificialIntelligence hashtag #TechIndustry hashtag #JavaScript hashtag #AppDevelopment hashtag #DevOps hashtag #DatabaseManagement hashtag #100DaysOfCode hashtag #TechCommunity hashtag #CodeNewbie Sushant Tiwari Shivam Tiwari https://lnkd.in/gPQGsa28
Reverse Integer - LeetCode
leetcode.com
To view or add a comment, sign in
-
Going through technical interviews can be stressful, so you'll want to prepare. Here's an analysis of 50 common Java interview questions and answers. In this guide, Vahe walks you through the code and explains the logic behind the examples.
The Java Interview Prep Handbook – 50 Questions Solved + Code Examples
freecodecamp.org
To view or add a comment, sign in
-
#Success Details Runtime: 5 ms, faster than 89.91% of Java online submissions for Count Subarrays Where Max Element Appears at Least K Times. Memory Usage: 66.4 MB, less than 5.24% of Java online submissions for Count Subarrays Where Max Element Appears at Least K Times. code: class Solution { public long countSubarrays(int[] nums, int k) { //[1,3,2,3,2,1,3] int left = 0; int right = 0; long ways = 0L; int n = nums.length; //max element in the array int max = 0; //times the max element has been appeared so far int maxFreq = 0; //the index where the max element is appeared for first time when maxFreq == k //when max element appears more than k times then firstAppearance will point the next //index from which int firstKAppearance = -1; while (left<=right && right<n){ if (nums[right] > max){ max = nums[right]; maxFreq = 1; ways = 0L; left = 0; firstKAppearance = right; } else if (nums[right] == max){ maxFreq++; } if (maxFreq == k){ left = firstKAppearance; ways+=(left+1); } else if (maxFreq > k){ while (left<=right && maxFreq > k){ if (nums[left] == max) maxFreq--; left++; } while(left<=right && nums[left] != max){ left++; } firstKAppearance = left; ways += (left+1); } right++; } return ways; } } You are given an integer array nums and a positive integer k. Return the number of subarrays where the maximum element of nums appears at least k times in that subarray. A subarray is a contiguous sequence of elements within an array. Example 1: Input: nums = [1,3,2,3,3], k = 2 Output: 6 Explanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3]. Example 2: Input: nums = [1,4,2,1], k = 3 Output: 0 Explanation: No subarray contains the element 4 at least 3 times.
Count Subarrays Where Max Element Appears at Least K Times - LeetCode
leetcode.com
To view or add a comment, sign in
-
Going through technical interviews can be stressful, so you'll want to prepare. Here's a rundown of 50 common Java interview questions + their answers. In this guide, Vahe walks you through the code and explains the logic behind the examples.
The Java Interview Prep Handbook – 50 Questions Solved + Code Examples
freecodecamp.org
To view or add a comment, sign in
-
#Success Details Runtime: 15 ms, faster than 96.06% of Java online submissions for Minimum Difference Between Largest and Smallest Value in Three Moves. Memory Usage: 56.8 MB, less than 76.12% of Java online submissions for Minimum Difference Between Largest and Smallest Value in Three Moves. code: class Solution { public int minDifference(int[] nums) { int n = nums.length; if (n<=4) return 0; Arrays.sort(nums); //we have 4 cases //1.replace the first 2 elements with the third and the last one with the pre last one int diff1 = nums[n-2]-nums[2]; //2.replace the last 3 elements with the fourth from the last int diff2 = nums[n-4]-nums[0]; //3.replace the first 3 elements with the fourth from the start int diff3 = nums[n-1]-nums[3]; //4. replace the last 2 elements with the third from the end and the first element with the second int diff4 = nums[n-3]-nums[1]; return Math.min(Math.min(diff1, diff2), Math.min(diff3, diff4)); } } You are given an integer array nums. In one move, you can choose one element of nums and change it to any value. Return the minimum difference between the largest and smallest value of nums after performing at most three moves. Example 1: Input: nums = [5,3,2,4] Output: 0 Explanation: We can make at most 3 moves. In the first move, change 2 to 3. nums becomes [5,3,3,4]. In the second move, change 4 to 3. nums becomes [5,3,3,3]. In the third move, change 5 to 3. nums becomes [3,3,3,3]. After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0. Example 2: Input: nums = [1,5,0,10,14] Output: 1 Explanation: We can make at most 3 moves. In the first move, change 5 to 0. nums becomes [1,0,0,10,14]. In the second move, change 10 to 0. nums becomes [1,0,0,0,14]. In the third move, change 14 to 1. nums becomes [1,0,0,0,1]. After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1. It can be shown that there is no way to make the difference 0 in 3 moves.
Minimum Difference Between Largest and Smallest Value in Three Moves - LeetCode
leetcode.com
To view or add a comment, sign in
-
#Success Details Runtime: 9 ms, faster than 99.22% of Java online submissions for Even Odd Tree. Memory Usage: 65.1 MB, less than 74.61% of Java online submissions for Even Odd Tree. code: class Solution { public boolean isEvenOddTree(TreeNode root) { Queue<TreeNode> qu = new ArrayDeque<>(); qu.add(root); boolean isEvenLevel = true; //if this node is the most left node at each level boolean mostLeftNode = true; //the previous node in the same level(traversing from left to right) int lastNumber = 0; while(!qu.isEmpty()){ int counter = qu.size(); while(counter>0){ TreeNode node = qu.poll(); counter--; if (mostLeftNode){ lastNumber = node.val; mostLeftNode = false; if (isEvenLevel && node.val % 2 == 0) return false; else if (!isEvenLevel && node.val%2 == 1) return false; } else{ if (isEvenLevel && (node.val %2 != 1 || node.val <= lastNumber)) return false; else if (!isEvenLevel && (node.val % 2 !=0 || node.val>=lastNumber)) return false; lastNumber = node.val; } if (node.left!=null) qu.add(node.left); if (node.right!=null) qu.add(node.right); } mostLeftNode = true; isEvenLevel = (isEvenLevel == true)?false:true; } return true; } } class Solution { public boolean isEvenOddTree(TreeNode root) { Queue<TreeNode> qu = new ArrayDeque<>(); qu.add(root); boolean isEvenLevel = true; //if this node is the most left node at each level boolean mostLeftNode = true; //the previous node in the same level(traversing from left to right) int lastNumber = 0; while(!qu.isEmpty()){ int counter = qu.size(); while(counter>0){ TreeNode node = qu.poll(); counter--; if (mostLeftNode){ lastNumber = node.val; mostLeftNode = false; if (isEvenLevel && node.val % 2 == 0) return false; else if (!isEvenLevel && node.val%2 == 1) return false; } else{ if (isEvenLevel && (node.val %2 != 1 || node.val <= lastNumber)) return false; else if (!isEvenLevel && (node.val % 2 !=0 || node.val>=lastNumber)) return false; lastNumber = node.val; } if (node.left!=null) qu.add(node.left); if (node.right!=null) qu.add(node.right); } mostLeftNode = true; isEvenLevel = (isEvenLevel == true)?false:true; } return true; } }
Even Odd Tree - LeetCode
leetcode.com
To view or add a comment, sign in
-
#Success Details Runtime: 900 ms, faster than 10.19% of Java online submissions for The Number of Beautiful Subsets. Memory Usage: 44.9 MB, less than 35.24% of Java online submissions for The Number of Beautiful Subsets. code: class Solution { int totalSubsets; public void dfs(int[] nums, Map<Integer, Integer> freq, int startingIndex, List<Integer> al, int difference){ int n = nums.length; if (n == startingIndex) return; for (int i=startingIndex;i<n;i++){ if (freq.get(nums[i]-difference) == null){ if (freq.get(nums[i]) == null) freq.put(nums[i], 1); else freq.put(nums[i], freq.get(nums[i])+1); al.add(nums[i]); this.totalSubsets++; dfs(nums, freq, i+1, al, difference); freq.put(nums[i], freq.get(nums[i])-1); if (freq.get(nums[i]) == 0) freq.remove(nums[i]); al.remove(al.size()-1); } } } public int beautifulSubsets(int[] nums, int k) { Map<Integer, Integer> freq = new HashMap<>(); List<Integer> al = new ArrayList<>(); Arrays.sort(nums); this.totalSubsets = 0; dfs(nums, freq,0, al, k); return this.totalSubsets; } } ou are given an array nums of positive integers and a positive integer k. A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k. Return the number of non-empty beautiful subsets of the array nums. A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different. Example 1: Input: nums = [2,4,6], k = 2 Output: 4 Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6]. It can be proved that there are only 4 beautiful subsets in the array [2,4,6].
The Number of Beautiful Subsets - LeetCode
leetcode.com
To view or add a comment, sign in
-
Ruby On Rails Interview bible book with 500+ Questions and Answers, JavaScript Bible with 1000+ Q&A. Python Handbook with 500+ Q&A. Free Python handbook 112+ Q&A. ReactJS with 112 Q&A! #ruby #javascript #python #reactjs #bundle https://lnkd.in/g--6fkB5
ð Ultimate Job Interview Preparation eBook Bundle
nezirzahirovic.gumroad.com
To view or add a comment, sign in
-
#Success Details Runtime: 0 ms, faster than 100.00% of Java online submissions for Delete Leaves With a Given Value. Memory Usage: 44.3 MB, less than 32.49% of Java online submissions for Delete Leaves With a Given Value. code: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public TreeNode dfs(TreeNode root, int target){ if (root == null) return null; TreeNode left = dfs(root.left, target); TreeNode right = dfs(root.right, target); root.left = left; root.right = right; if (root.val == target && root.left == null && root.right == null) root = null; return root; } public TreeNode removeLeafNodes(TreeNode root, int target) { return dfs(root, target); } } Given a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot). Example 1: Input: root = [1,2,3,2,null,2,4], target = 2 Output: [1,null,3,null,4] Explanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). After removing, new nodes become leaf nodes with value (target = 2) (Picture in center). Example 2: Input: root = [1,3,3,3,2], target = 3 Output: [1,3,null,null,2] Example 3: Input: root = [1,2,null,2,null,2], target = 2 Output: [1] Explanation: Leaf nodes in green with value (target = 2) are removed at each step.
Delete Leaves With a Given Value - LeetCode
leetcode.com
To view or add a comment, sign in