Tip 1 : Always remember question-solving is not everything in the interview, its a part of interview. Communicating well with the interviewer is most important thing during the interview.
Tip 2 : Also practice lot of Data Structures and Algorithms based questions that I have practiced from Coding Ninjas and on other coding portals.
Tip 1 : Never leave any topic from any chapter / Subject
Tip 2 : Learn to explain your thoughts well
Tip 3 : Learn from previous experiences / interviews / problems asked.
Tip 4 : Atleast 4 projects in Resume



The pair consists of equal absolute values, one being positive and another negative.
Return an empty array, if no such pair exists.
I asked for some clarifications whether I should print all distinct x‘s or if I should print an x if a pair of +x and -x is encountered. The first approach I told was to use a map and I was keeping a flag for +x and -x if it’s found once. Later he asked me to print all pairs, so I stored the frequencies of all the elements in the map and iterated through the negative elements and for each element x , I would print x min(count[-x],count[+x]) times. He said he can’t afford that much space and he wanted me to optimise space further. So I told him a 2 pointer approach where I sort the array once and then keep two pointers to the start and end. I would move the start pointer forward if the sum is less than 0 and I’ll move the end pointer backward if the sum is greater than 0. He was fine with the solution and asked me to code it in a paper. I wrote the code and walked him through it.



Use zero-based indexing for the nodes.
The tree is always rooted at 0.
Simple BFS worked



Input: ‘n’ = 7
Output: 2
Explanation:
The square root of the number 7 lies between 2 and 3, so the floor value is 2.
So he asked me to explain all approaches from brute force to the optimal solution, which he was expecting me to do in O(logn), and use different methods for each implementations(different methods in same code).



I solved it using backtracking



This was solved by me through dynamic programming. Let dp[i][j] denote the maximum possible weight you can fill in the bag with a total capacity of j using exactly one stone of each color from 1 to i. Now you can club all same-colored stones in a vector. Then this problem is same as the classical knapsack problem and I passed all test cases



[1, 2, 3, 4] is a strictly increasing array, while [2, 1, 4, 3] is not.
Firstly I gave recursion approach but then the interviewer asked me to optimize that so I gave him a standard DP approach for the longest increasing subsequences by storing the result and use them for future calculations of bigger problem.

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