Tip 1 : Practice Atleast 250 Questions
Tip 2 : Do atleast 2 projects
Tip 3 : practice basics of dsa
Tip 1 : show your projects
Tip 2 : highlight your skills
3 coding question + 50 dsa



A majority element is an element that occurs more than floor('N' / 2) times in the array.
Approach: The basic solution is to have two loops and keep track of the maximum count for all different elements. If maximum count becomes greater than n/2 then break the loops and return the element having maximum count. If the maximum count doesn’t become more than n/2 then the majority element doesn’t exist.
Algorithm:
Create a variable to store the max count, count = 0
Traverse through the array from start to end.
For every element in the array run another loop to find the count of similar elements in the given array.
If the count is greater than the max count update the max count and store the index in another variable.
If the maximum count is greater than the half the size of the array, print the element. Else print there is no majority element.



Input: Let the binary tree be:

Output: 2
Explanation: The root node is 3, and the leaf nodes are 1 and 2.
There are two nodes visited when traversing from 3 to 1.
There are two nodes visited when traversing from 3 to 2.
Therefore the height of the binary tree is 2.
maxDepth()
1. If tree is empty then return -1
2. Else
(a) Get the max depth of left subtree recursively i.e.,
call maxDepth( tree->left-subtree)
(a) Get the max depth of right subtree recursively i.e.,
call maxDepth( tree->right-subtree)
(c) Get the max of max depths of left and right
subtrees and add 1 to it for the current node.
max_depth = max(max dept of left subtree,
max depth of right subtree)
+ 1
(d) Return max_depth



A cell in 2D matrix can be connected to 8 neighbours. So, unlike standard DFS(), where we recursively call for all adjacent vertices, here we can recursively call for 8 neighbours only. We keep track of the visited 1s so that they are not visited again.
2 coding questions



Given Pairs = [3,4], [1,2], [2,3].
The length of the maximum chain will be 2. The longest chain is [1,2] -> [3,4].
1. You can select a pair only once.
2. You needn’t use up all the given pairs.
3. You can select pairs in any order.
This problem is a variation of standard Longest Increasing Subsequence problem. Following is a simple two step process.
1) Sort given pairs in increasing order of first (or smaller) element. Why do not need sorting? Consider the example {{6, 8}, {3, 4}} to understand the need of sorting. If we proceed to second step without sorting, we get output as 1. But the correct output is 2.
2) Now run a modified LIS process where we compare the second element of already finalized LIS with the first element of new LIS being constructed.



You must sell the stock before you buy it again.
If we are allowed to buy and sell only once, then we can use the following algorithm. Maximum difference between two elements. Here we are allowed to buy and sell multiple times.
Following is the algorithm for this problem.
Find the local minima and store it as starting index. If not exists, return.
Find the local maxima. And store it as an ending index. If we reach the end, set the end as the ending index.
Update the solution (Increment count of buy-sell pairs)
Repeat the above steps if the end is not reached.
Data structures,java script,web dev related questions,dbms questions
Design a Web Crawler.

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?