Tip 1: Practice at least 250 coding problems.
Tip 2: Work on at least 2 real-world projects.
Tip 3: Consistently revise the key concepts mentioned and take mock interviews.
Tip 1: Include some projects on your resume.
Tip 2: Do not put false information on your resume.



1. The array follows 0-based indexing, so you need to return the 0-based index of the element.
2. Note that the element at the equilibrium index won’t be considered for either left sum or right sum.
3. If there are multiple indices which satisfy the given condition, then return the left-most index i.e if there are indices i,j,k…. which are equilibrium indices, return the minimum among them
4. If no such index is present in the array, return -1.
Brute force approach - The fundamental approach involves using nested loops.
Outer Loop: Iterate through each element of the array, treating it as the "Pivot" element.
Inner Loop: For each Pivot element, check if it is an equilibrium index by comparing the sum of elements to its left with the sum of elements to its right.
You are given a string S consisting of letters 'a' and/or 'b'. A block is a consecutive fragment of S composed of the same letters and surrounded by different letters or string endings. For example, S = "abbabbaaa" has five blocks: "a", "bb", "a", "bb" and "aaa".
What is the minimum number of additional letters needed to obtain a string?
containing blocks of equal lengths? Letters can be added only at the
beginning or at the end of an existing block.
Traverse the String: Identify and count the lengths of contiguous blocks of the same character.
Calculate Maximum Block Length: Find the length of the longest block from the previously identified blocks.
Compute Additional Letters:
For each block, calculate the difference between the maximum length and the block’s length.
Sum these differences to get the total number of additional letters required.
A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, measured in seconds. The goal is to find the earliest time when the frog can jump to the other side of the river. The frog can cross only when leaves appear at every position across the river from 1 to X (that is, we want to find the earliest moment when all the positions from 1 to X are covered by leaves). You may assume that the speed of the current in the river is negligibly small, i.e. the leaves do not change their positions once they fall into the river.
Track Covered Positions: Use a boolean array or a set to keep track of which positions (from 1 to X) have been covered by falling leaves.
Iterate Through the Array: Traverse the array of falling leaves and update the tracking structure to mark the covered positions.
Check for Complete Coverage: As you process each leaf, check if all required positions (1 to X) have been covered.
Return the Earliest Time: The first time you encounter a moment when all positions from 1 to X are covered is the earliest time when the frog can jump to the other side.



You are given the array ‘ARR’ = [1, 1, 1, 1, 1], ‘TARGET’ = 3. The number of ways this target can be achieved is:
1. -1 + 1 + 1 + 1 + 1 = 3
2. +1 - 1 + 1 + 1 + 1 = 3
3. +1 + 1 - 1 + 1 + 1 = 3
4. +1 + 1 + 1 - 1 + 1 = 3
5. +1 + 1 + 1 + 1 - 1 = 3
These are the 5 ways to make. Hence the answer is 5.
The brute force approach relies on recursion, where we explore placing both + and - signs at each position in the given `nums` array to find the combinations that result in the target sum S.
I used a recursive function `calculate(nums, i, sum, S)` to determine the number of valid assignments. This function starts from the ith index, with the current sum up to that point being `sum`. It adds both a + and a - sign to the element at the current index, then recursively calls itself with the updated sum as `sum + nums[i]` and `sum - nums[i]`, and the updated index as `i + 1`. When the end of the array is reached, the resulting sum is compared with S, and if they match, the count is incremented.
Finally, the call to `calculate(nums, 0, 0, S)` returns the total number of assignments that achieve the desired sum.



You may assume that duplicates do not exist in the tree.
For the given tree shown below:

For the binary tree shown in the figure, if ‘X’ = 6, the output will be 1 as node value 6 is present in the BST.
To find a given element in a Binary Search Tree (BST) without using recursion, start by initializing the current node with the root of the BST. Then, enter a loop that continues until the current node becomes null. Within the loop, check if the current node's value matches the target value; if it does, return the current node (or True if you're only checking for existence). If the target value is less than the current node's value, move to the left child; if it's greater, move to the right child. If you reach a null node, the element is not in the tree. If the loop ends without finding the target, return null (or False if only checking for existence).



If the given array is [1, 3, 2], then you need to return [3, -1, -1]. Because for 1, 3 is the next greater element, for 3 it does not have any greater number to its right, and similarly for 2.
Understand the Problem:
You are given two arrays, nums1 and nums2. All elements in nums1 are present in nums2, and the order in nums2 matters.
The goal is to find, for each element in nums1, the first element to its right in nums2 that is larger.
Constraints and Edge Cases:
Consider edge cases where nums1 or nums2 might be empty.
Handle scenarios where no element to the right is greater.
Optimal Solution:
A brute force approach would involve nested loops, but this would be inefficient with a time complexity of O(n*m), where n is the length of nums1 and m is the length of nums2.
Instead, use a stack and a hash map to achieve this in O(m + n) time.
Using a Stack and Hash Map:
Traverse nums2 from right to left. Use a stack to keep track of elements for which we haven't yet found a greater element.
As you iterate through nums2, compare each element with the top of the stack. If the current element is greater than the stack's top element, pop the stack and record the current element as the next greater element for that popped element.
Store these results in a hash map for quick lookup.
Finally, for each element in nums1, simply look up its next greater element in the hash map.
System Design of Instagram.
Write a SQL query to find the 3rd Highest Salary in the table.
Write a SQL query to fetch the Employee name (in the Employee table) and Project name (in the Project table) having the same project ID.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
How do you remove whitespace from the start of a string?