Tip 1 - Practice at least 250 Questions from coding ninjas
Tip 2 - Do at least 2 good projects
Tip 1 : Have some projects on resume.
Tip 2 : Do not put false things on resume and be confident.
Two coding questions were asked
1. A sequence [arr0, arr1,…, arr(n-1)] is called an Arithmetic progression if for each 'i' ( 0 ≤ i < n - 1) the value arr[i+1] − arr[i] is the same.
2. There is exactly one missing number in the given sequence.
3. All the numbers present in the sequence are distinct.
4. It is the guarantee that the first and last elements of the sequence are not missing elements.
The overall run time complexity should be O(log(N)).
The idea is to go to the middle element. Check if the difference between middle and next to middle is equal to diff or not, if not then the missing element lies between mid and mid+1. If the middle element is equal to n/2th term in Arithmetic Series (Let n be the number of elements in input array), then missing element lies in right half. Else element lies in left half.
Input: Let the binary tree be:
Output: [10, 4, 2, 1, 3, 6]
Explanation: Consider the vertical lines in the figure. The top view contains the topmost node from each vertical line.
I solved using vertical order traversal
In the following directed graph has a cycle i.e. B->C->E->D->B.
1. The cycle must contain at least two nodes.
2. It is guaranteed that the given graph has no self-loops in the graph.
3. The graph may or may not be connected.
4. Nodes are numbered from 1 to N.
5. Your solution will run on multiple test cases. If you are using global variables make sure to clear them.
Depth First Traversal can be used to detect a cycle in a Graph
In the below graph, there exists a cycle between vertex 1, 2 and 3.
1. There are no parallel edges between two vertices.
2. There are no self-loops(an edge connecting the vertex to itself) in the graph.
3. The graph can be disconnected.
Input: N = 3 , Edges = [[1, 2], [2, 3], [1, 3]].
Output: Yes
Explanation : There are a total of 3 vertices in the graph. There is an edge between vertex 1 and 2, vertex 2 and 3 and vertex 1 and 3. So, there exists a cycle in the graph.
To detect if there is any cycle in the undirected graph or not, we will use the DFS traversal for the given graph. For every visited vertex v, when we have found any adjacent vertex u, such that u is already visited, and u is not the parent of vertex v. Then one cycle is detected.
Down: (row+1,col)
Right: (row, col+1)
Down right diagonal: (row+1, col+1)
Use recursion to solve this problem
There are 25 horses among which you need to find out the fastest 3 horses. You can conduct race among at most 5 to find out their relative speed. At no point you can find out the actual speed of the horse in a race. Find out the minimum no. of races which are required to get the top 3 horses.
First, we group the horses into groups of 5 and race each group on the race course. This gives us 5 races.
Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What does the SQL function NOW() return?