Tip 1 : Focus on graphs every interviewer ask at least one graph question
Tip 2 : Read about amazon leadership principles and STAR
Tip 3 : Make 2-3 good personal projects, interviewers ask about questions about personal projects.
Tip 1 : Make 2-3 good personal projects, interviewers ask about questions about personal projects.
Tip 2 : Make a single page resume
Interviewer was helpful and was giving hints when I was struck.



1. Coordinates of the cells are given in 0-based indexing.
2. You can move in 4 directions (Up, Down, Left, Right) from a cell.
3. The length of the path is the number of 1s lying in the path.
4. The source cell is always filled with 1.
1 0 1
1 1 1
1 1 1
For the given binary matrix and source cell(0,0) and destination cell(0,2). Few valid paths consisting of only 1s are
X 0 X X 0 X
X X X X 1 X
1 1 1 X X X
The length of the shortest path is 5.



I came up with the O(nˆ2) approach by detecting the cycle first then traversing the list to find the point where the cycle starts.
then optimised it to O(n) using hashmap
Coding. + Behavioural round
Interview included discussion about personal projects and asked about motivation to make that project.


‘N’ = 5, ‘K’ = 4, ‘nums’ = [2, 6, 1, 7, 8]
Output: 5
Explanation: (1, 2), (1, 5), (2, 5), (3, 5), and (4, 5) pairs have their products divisible by K.



‘GRID’ =

We cannot reach the cell ‘(2, 2)’ until the time is ‘5’. When the time is ‘5’, we move along the path:
0 -> 1 -> 4 -> 3 -> 5
The cell with value ‘1’ will be unlocked when the time is ‘1’.
At time = 1: 0 -> 1
Similarly, the cell with value ‘4’ is unlocked when the time is ‘4’. At that time the cell with value ‘3’ will also be unlocked, as it unlocks at time ‘3’.
At time = 4: 0 -> 1 -> 4 -> 3
The cell with value ‘5’ will be unlocked when the time is ‘5’.
At time = 5: 0 -> 1 -> 4 -> 3 -> 5
So, the least time to reach cell ‘(2, 2)’ is ‘5’.
1. All elements in the ‘GRID’ are unique.
2. ‘GRID[i][j]’ is a permutation of [0, 1, … , (N ^ 2) - 1].
I came up with the O(nˆ2) approach initially then optimised it using DP and did it in O(n)



Consider 0-based indexing.
Consider the array 1, 2, 3, 4, 5, 6
We can Jump from index 0 to index 1
Then we jump from index 1 to index 2
Then finally make a jump of 3 to reach index N-1
There is also another path where
We can Jump from index 0 to index 1
Then we jump from index 1 to index 3
Then finally make a jump of 2 to reach index N-1
So multiple paths may exist but we need to return the minimum number of jumps in a path to end which here is 3.



Let ‘N’ = 4, ‘Arr’ be [1, 2, 5, 4] and ‘K’ = 3.
then the elements of this array in ascending order is [1, 2, 4, 5]. Clearly, the 3rd smallest and largest element of this array is 4 and 2 respectively.



insert(X): Inserts an element X in the data structure and returns true if the element was not present, and false otherwise.
remove(X): Removes the element X from the data structure, if present. Returns true if the element was present and false otherwise.
search(X): Search the element X in the data structure. Returns true if the element was present and false otherwise.
getRandom(): Return a random element present in the data structure.
Type 1: for insert(X) operation.
Type 2: for remove(X) operation.
Type 3: for search(X) operation.
Type 4: for getRandom() operation.
It is guaranteed that at least one element will be present in the data structure when getRandom() operation is performed.
Can you implement every operation such that it works in O(1) time?

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?