Tip 1 : Practice popular questions from Arrays, Binary Trees, and LinkedList from CodeStudio's Interview Problems
Tip 2 : Make sure you are aware of calculating the time and space complexity for every problem you're coding.
Tip 3 : Prepare through Mock Interviews to practice explaining your approach while solving in an actual interview.
Tip 1 : Describe the best of your projects in minimum words. Don't forget to add buzzwords like REST APIs/ DB Indexing/ Benchmarking etc if you worked on the backend.
Tip 2 : Don't add school achievements like Class Topper in your resume.
Tip 3 : If you've some work experience, put it in a way you're marketing yourself. Add terms like 'Created/Owned the Project through the entire SDLC.
One coding question, some general talk & questions on puzzle



The diameter of a binary tree is the length of the longest path between any two end nodes in a tree.
The number of edges between two nodes represents the length of the path between them.
Input: Consider the given binary tree:

Output: 6
Explanation:
Nodes in the diameter are highlighted. The length of the diameter, i.e., the path length, is 6.
int height(TreeNode* root,int *x)
{
int lh=0;
int rh=0;
int ld=0;
int rd=0;
if(root==NULL)
return 0;
ld=height(root->left,&lh);
rd=height(root->right,&rh);
*x=max(lh,rh)+1;
return max(lh+rh+1,max(ld,rd));
}
int diameterOfBinaryTree(TreeNode* root) {
int x=0;
return height(root,&x)-1;
}
Make a fair coin from a biased coin.
You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40% probability. Write a new function that returns 0 and 1 with a 50% probability each. Your function should use only foo(), no other library method.
We know foo() returns 0 with 60% probability. How can we ensure that 0 and 1 are returned with a 50% probability?
The solution is similar to this post. If we can somehow get two cases with equal probability, then we are done. We call foo() two times. Both calls will return 0 with a 60% probability. So the two pairs (0, 1) and (1, 0) will be generated with equal probability from two calls of foo(). Let us see how.
(0, 1): The probability to get 0 followed by 1 from two calls of foo() = 0.6 * 0.4 = 0.24
(1, 0): The probability to get 1 followed by 0 from two calls of foo() = 0.4 * 0.6 = 0.24
So the two cases appear with equal probability. The idea is to return consider only the above two cases, return 0 in one case, return 1 in other case. For other cases [(0, 0) and (1, 1)], recur until you end up in any of the above two cases.



Two strings are said to be anagram if they contain the same characters, irrespective of the order of the characters.
If 'STR1' = “listen” and 'STR2' = “silent” then the output will be 1.
Both the strings contain the same set of characters.
bool isAnagram(string s, string t) {
int a[256]={0};
for(int i=0;i {
a[s[i]]++;
}
for(int i=0;i {
a[t[i]]--;
}
for(int i=0;i<256;i++)
if(a[i]!=0)
return false;
return true;
}



1. There are no 2 adjacent elements having same value (as mentioned in the constraints).
2. Do not print anything, just return the index of the peak element (0 - indexed).
3. 'True'/'False' will be printed depending on whether your answer is correct or not.
Input: 'arr' = [1, 8, 1, 5, 3]
Output: 3
Explanation: There are two possible answers. Both 8 and 5 are peak elements, so the correct answers are their positions, 1 and 3.
int findPeakElement(vector& nums) {
int max=-2147483648;
int pos=0;
for(int i=0;imax)
{
max=nums[i];
pos=i;
}
}
return pos;
}



Input: 'a' = [2, 4, 6] and 'b' = [1, 3, 5]
Output: 3.5
Explanation: The array after merging 'a' and 'b' will be { 1, 2, 3, 4, 5, 6 }. Here two medians are 3 and 4. So the median will be the average of 3 and 4, which is 3.5.
The given arrays are sorted, so merge the sorted arrays in an efficient way and keep the count of elements inserted in the output array or printed form. So when the elements in the output array are half the original size of the given array print the element as a median element. There are two cases:
Case 1: m+n is odd, the median is at (m+n)/2 th index in the array obtained after merging both the arrays.
Case 2: m+n is even, the median will be the average of elements at index ((m+n)/2 – 1) and (m+n)/2 in the array obtained after merging both the arrays



You don’t have to multiply the matrices, you only have to find the minimum number of multiplication operations.
ARR = {2, 4, 3, 2}
Here, we have three matrices with dimensions {2X4, 4X3, 3X2} which can be multiplied in the following ways:
a. If the order of multiplication is (2X4, 4X3)(3X2), then the total number of multiplication operations that need to be performed are: (2*4*3) + (2*3*2) = 36
b. If the order of multiplication is (2X4)(4X3, 3X2), then the total number of multiplication operations that need to be performed are (2*4*2) + (4*3*2) = 40
Create a recursive function that takes i and j as parameters that determines the range of a group.
Iterate from k = i to j to partition the given range into two groups.
Call the recursive function for these groups.
Return the minimum value among all the partitions as the required minimum number of multiplications to multiply all the matrices of this group.
The minimum value returned for the range 0 to N-1 is the required answer.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?