Tip 1 - Practice Atleast 250 Questions
Tip 2 - Ex- Do atleast 2 projects
Tip 1 : Have some projects on resume.
Tip 2 : Do not put false things on resume



A sequence a1, a2, .... an is called an alternating sequence if its elements satisfy one of the following relations : a1 < a2 > a3 < a4 > a5..... or a1 > a2 < a3 > a4 < a5.
'ARR' = {3, 10, 1, 2, 30}, the longest alternating subsequence for this array can be {3, 10, 1, 30} or {3, 10, 2, 30}. Therefore, the answer will be 4.
This problem is an extension of longest increasing subsequence problem, but requires more thinking for finding optimal substructure property in this.
We will solve this problem by dynamic Programming method, Let A is given array of length n of integers. We define a 2D array las[n][2] such that las[i][0] contains longest alternating subsequence ending at index i and last element is greater than its previous element and las[i][1] contains longest alternating subsequence ending at index i and last element is smaller than its previous element, then we have following recurrence relation between them,



You may assume that given ‘X’ and ‘Y’ definitely exist in the given binary tree.
For the given binary tree

LCA of ‘X’ and ‘Y’ is highlighted in yellow colour.
The idea of this approach is to store the path from the root to n1 and root to n2 in two separate data structures. Then look simultaneously into the values stored in the data structure, and look for the first mismatch.
the interviewer was friendly. He firstly ask me questions from my resume and then give coding problem to solve



1. The array may contain duplicate elements.
2. The array can also contain negative integers.
3. Every element of the subsequence must be greater than or equal to the previous element.
This problem is similar to Longest Increasing Subsequence (LIS) problem. and can be solved using Dynamic Programming.
Create two empty array that store result of maximum
sum of alternate sub-sequence
inc[] : inc[i] stores results of maximum sum alternating
subsequence ending with arr[i] such that arr[i]
is greater than previous element of the subsequence
dec[] : dec[i] stores results of maximum sum alternating
subsequence ending with arr[i] such that arr[i]
is less than previous element of the subsequence
Include first element of 'arr' in both inc[] and dec[]
inc[0] = dec[0] = arr[0]
// Maintain a flag i.e. it will makes the greater
// elements count only if the first decreasing element
// is counted.
flag = 0
Traversal two loops
i goes from 1 to n-1
j goes 0 to i-1
IF arr[j] > arr[i]
dec[i] = max(dec[i], inc[j] + arr[i])
// Denotes first decreasing is found
flag = 1
ELSE IF arr[j] < arr[i] && flag == 1
inc[i] = max(inc[i], dec[j]+arr[i]);
Final Last Find maximum value inc[] and dec[] .



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 ] ]
To solve the question without any extra space, rotate the array in form of squares, dividing the matrix into squares or cycles. For example,
A 4 X 4 matrix will have 2 cycles. The first cycle is formed by its 1st row, last column, last row, and 1st column. The second cycle is formed by the 2nd row, second-last column, second-last row, and 2nd column. The idea is for each square cycle, to swap the elements involved with the corresponding cell in the matrix in an anti-clockwise direction i.e. from top to left, left to bottom, bottom to right, and from right to top one at a time using nothing but a temporary variable to achieve this



You need to return the head to the doubly linked list.
The doubly linked list would be: 1 2 3 4 5 and can be represented as:

we traverse the tree in inorder fashion. We add nodes at the beginning of current linked list and update head of the list using pointer to head pointer. Since we insert at the beginning, we need to process leaves in reverse order. For reverse order, we first traverse the right subtree before the left subtree. i.e. do a reverse inorder traversal.
1. what other skills do u have apart from coding.
2. Are u willing to relocate?
3. what if u get a package higher from amazon . Will u accept that offer?

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?