Tip 1 : Good Knowledge of Time and Space Complexity
Tip 2 : Practice DSA Questions
Tip 1 : Have some projects on your resume.
Tip 2 : Do not put false things on your resume.



In the given linked list, there is a cycle, hence we return true.

Step 1) Have a visited flag with each node.
Step 2) Traverse the linked list and keep marking visited nodes.
Step 3) If you see a visited node again then there is a loop. This solution works in O(n) but requires additional information with each node.


If the given matrix is:
[ [1, 2, 5],
[3, 4, 9],
[6, 7, 10]]
We have to find the position of 4. We will return {1,1} since A[1][1] = 4.
Step 1) Let the given element be x, create two variable i = 0, j = n-1 as index of row and column
Step 2) Run a loop until i = n
Step 3) Check if the current element is greater than x then decrease the count of j. Exclude the current column.
Step 4) Check if the current element is less than x then increase the count of i. Exclude the current row.
Step 5) If the element is equal, then print the position and end.



If the given list is (1 -> -2 -> 0 -> 4) and N=2:

Then the 2nd node from the end is 0.
Step 1) Calculate the length of the Linked List. Let the length be len.
Step 2) Print the (len – n + 1)th node from the beginning of the Linked List.



For given 2D array :
[ [ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ] ]
After 90 degree rotation in anti clockwise direction, it will become:
[ [ 3, 6, 9 ],
[ 2, 5, 8 ],
[ 1, 4, 7 ] ]
Step 1) There is N/2 squares or cycles in a matrix of side N. Process a square one at a time. Run a loop to traverse the matrix a cycle at a time, i.e loop from 0 to N/2 – 1, loop counter is i
Step 2) Consider elements in group of 4 in current square, rotate the 4 elements at a time. So the number of such groups in a cycle is N – 2*i.
Step 3) So run a loop in each cycle from x to N – x – 1, loop counter is y
Step 4) The elements in the current group is (x, y), (y, N-1-x), (N-1-x, N-1-y), (N-1-y, x), now rotate the these 4 elements, i.e (x, y) <- (y, N-1-x), (y, N-1-x)<- (N-1-x, N-1-y), (N-1-x, N-1-y)<- (N-1-y, x), (N-1-y, x)<- (x, y)
Step 5) Print the matrix.

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?