Tip 1 : Practice DP based questions as much as you can. Also, be confident during the interview about your solution.
Tip 2 : For practice, you can prefer Coding Ninjas and Geeks For Geeks.
Tip 1 : Keep it short. Mention the academic and professional projects you've done. Add your educational details properly with percentage or CGPA obtained.
Tip 2 : Must atleast two project.



Write an efficient program to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.
I used Kadane algorithm here to find subarray with maximum sum. It is a standard question for interview.



For 'N' : 4
Pattern :
4 3 2 1 2 3 4
3 3 2 1 2 3 3
2 2 2 1 2 2 2
1 1 1 1 1 1 1
2 2 2 1 2 2 2
3 3 2 1 2 3 3
4 3 2 1 2 3 4
I simply use for and while loops with some conditions and printed the required pattern.



V is the number of vertices present in graph G and vertices are numbered from 0 to V-1.
E is the number of edges present in graph G.
The Graph may not be connected i.e there may exist multiple components in a graph.
As I have to find a number of connected components in an undirected graph so I simply use Depth-first search to solve this question by visiting each element and mapped it to the number of component in which it belongs. At last, I print the vertices of each component.


You can’t sell without buying first.
For the given array [ 2, 100, 150, 120],
The maximum profit can be achieved by buying the stock at minute 0 when its price is Rs. 2 and selling it at minute 2 when its price is Rs. 150.
So, the output will be 148.



As this value might be large, print it modulo 10^9 + 7
For this question, I simply used some mathematics and considered the frequency of each element and their contribution to subsequences. Wrote its fully commented code with neat handwriting.



1. Delete a character
2. Replace a character with another one
3. Insert a character
Strings don't contain spaces in between.
Firstly I gave the interviewer, a recursive solution then he asked me to reduce complexity as it was exponential of recursive solution so I gave him a top-down DP solution.



A sequence 'A' is a subsequence of a sequence 'B' if 'A' can be obtained from 'B' by deletion of several (possibly, zero) elements. For example, [3,1] is a subsequence of [3,2,1] and [4,3,1], but not a subsequence of [1,3,3,7] and [3,10,4].
I initially tried a 2D DP solution where dp[i][j] indicates the length of the longest sequence with ending at i containing j as a digit. It’s a N X 10 DP matrix. The interviewer asked me why I needed a 2D DP solution and I struggled to convince him. I wrote the code for it. It wasn’t completely correct. I was missing something. After thinking for a while I narrowed down to a solution containing only 10 elements dp[0], dp[1], dp[2].. dp[9] which is updated every time I see a new number. I take a number, I go through all digits in the number and find value = 1 + max(dp[d] for all digits d in the number). Set this value to dp[d] for all digits in the number. He gave a hint to take the max and finally gave a solution to the interviewer and he was satisfied with that solution.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
To make an AI less repetitive in a long paragraph, you should increase: