Tip 1: Practice at least 4-5 questions daily.
Tip 2: Prepare a good script for your projects.
Tip 1: Have 2-3 strong projects.
Tip 2: List only those skills in which you are confident.



Given an integer array nums[] and an integer k, return the k most frequent elements in the array.
Step 1: Initially, I thought of sorting the array based on frequency and then selecting the top k elements. But sorting would take O(n log n) time, which wasn’t ideal.
Step 2: To optimize, I used a hash map to count the frequency of each element, and then a min-heap to keep track of the top k frequent elements. This reduced the time complexity to O(n log k).
Step 3: I implemented this approach in the online assessment, which efficiently passed all test cases.



A subsequence of an array/list is obtained by deleting some number of elements (can be zero) from the array/list, leaving the remaining elements in their original order.
Step 1: I started by thinking about a recursive solution where I would decide for each element whether to include it in the subsequence or not, but this approach would result in exponential time complexity, O(2^n), due to the overlapping subproblems.
Step 2: To optimize, I transformed the problem into a dynamic programming problem where I maintained an array dp[] where dp[i] represented the maximum sum of subsequences considering the first i elements.
Step 3: The recurrence relation I used was dp[i] = max(dp[i-1], arr[i] + dp[i-2]). The idea was to either include the current element and add it to the sum excluding the previous one, or to exclude the current element and carry forward the previous maximum sum. The solution had a time complexity of O(n) and a space complexity of O(n), and passed all test cases during the assessment.



‘N’ = 3, ‘coins’ = {1, 2, 3}, ‘freq’ = {1, 1, 3}, ‘V’ = 6
For the given example, we can make six by using the following coins:
{1, 2, 3}
{3. 3}
Hence, the answer is 2.
Step 1: I started with a brute-force approach, where I would generate all possible combinations of coins and count the ones that sum up to the target amount. However, this approach was inefficient with a time complexity of O(2^n), especially for larger inputs.
Step 2: The interviewer asked if I could optimize the solution. I then switched to a dynamic programming approach. I defined a dp[] array where dp[i] represented the number of combinations that sum up to the amount i. The idea was to iteratively build up the number of combinations for increasing amounts.
Step 3: I used the recurrence relation: for each coin in coins[], I updated the dp[] array by adding dp[i - coin] to dp[i] for all amounts i from coin to amount. This efficiently counted the number of ways to form each amount. I initialized dp[0] = 1 since there is exactly one way to make the amount 0 (using no coins). The final time complexity of this solution was O(n * m), where n is the amount and m is the number of coins. The approach was effective and met the interviewer’s expectations.



For Amount = 70, the minimum number of coins required is 2 i.e an Rs. 50 coin and a Rs. 20 coin.
It is always possible to find the minimum number of coins for the given amount. So, the answer will always exist.
Step 1: I started by understanding that this problem is a variation of the knapsack problem where we need to maximize the value of coins picked from multiple piles with the constraint of picking exactly k coins. The problem involves both optimization and combination aspects.
Step 2: The interviewer suggested using dynamic programming to solve this efficiently. I defined a DP table dp[j], where dp[j] represents the maximum total value of coins we can collect by picking exactly j coins.
Step 3: For each pile, I calculated the cumulative sum of coins from the top up to x coins. I then iteratively updated the DP table by considering each possible number of coins that could be picked from the current pile and updating the maximum values in dp[].
Step 4: Specifically, for each pile, I used a temporary array to store intermediate results and updated the DP table in a way that ensures previous results are used optimally. The final solution was obtained by processing each pile and updating the DP array according to the possible number of coins that could be picked from the pile.
Step 5: I ensured that the solution handles edge cases such as piles with fewer coins than k and large values of k. The approach had a time complexity of O(n * k^2) and efficiently calculated the maximum total value of coins. The solution was validated against various test cases during the interview.
Hiring Manager Round
You went to a bank to cash your check. The bank clerk accidentally gives you: The dollar amount is in cents, and the cent amount is in dollars. You spend 5 cents on the way home and then realize you have twice the amount of your cheque. What was the actual amount that was written on the cheque?
Design a snake ladder game? (Learn)

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?