Tip 1 : Consistency
Tip 2 : Never Give Up
Tip 3 : Learn from the mistakes
Tip 1 : Simple and short providing the required information
Tip 2 : Single page resume with showing all the multiple projects which have done.
The first round consisted of three algorithmic questions conducted on Hacker rank. They were tough questions



For the given arr[ ] = { -1, 3, 5, 0, -2, -5 }
arr[ ] = {3, -1, 5, -2, 0, -5 } is valid rearrangement.
arr[ ] = {3, -1, 0, -2, 5, -5 } is invalid rearrangement; order of 0 and 5 is changed.
arr[ ] = {3, -1, 5, 0, -2, -5 } is invalid rearrangement; positive and negative elements are not alternative.
Make changes in the same array and no returning or printing is needed.
Consider zero(0) as a positive element for this question.
It is guaranteed that an answer always exists.
First, sort the array in non-increasing order. Then we will count the number of positive and negative integers.
Then swap the one negative and one positive number in the odd positions till we reach our condition.
This will rearrange the array elements because we are sorting the array and accessing the element from left to right according to our need.
Time Complexity: O(N*logN)
Space Complexity: O(1)



Each product can cross the integer limits, so we should take modulo of the operation.
Take MOD = 10^9 + 7 to always stay in the limits.
Can you try solving the problem in O(1) space?
Create two array prefix and suffix of length n, i.e length of the original array, initialize prefix[0] = 1 and suffix[n-1] = 1 and also another array to store the product.
Traverse the array from second index to end.
For every index i update prefix[i] as prefix[i] = prefix[i-1] * array[i-1], i.e store the product upto i-1 index from the start of array.
Traverse the array from second last index to start.
For every index i update suffix[i] as suffix[i] = suffix[i+1] * array[i+1], i.e store the product upto i+1 index from the end of array
Traverse the array from start to end.
For every index i the output will be prefix[i] * suffix[i], the product of the array element except that element.
Time Complexity: O(n).
The array needs to be traversed three times, so the time complexity is O(n).
Space Complexity: O(n).
Two extra arrays and one array to store the output is needed so the space complexity is O(n)



Input: 'arr1' = [2, 3, 45], 'arr2' = [4, 6, 7, 8] and 'k' = 4
Output: 6
Explanation: The merged array will be [2, 3, 4, 6, 7, 8, 45]. The element at position '4' of this array is 6. Hence we return 6.
Since we are given two sorted arrays, we can use the merging technique to get the final merged array. From this, we simply go to the k’th index.
Divide And Conquer Approach
While the previous method works, can we make our algorithm more efficient? The answer is yes. By using a divide and conquer approach, similar to the one used in binary search, we can attempt to find the k’th element in a more efficient way.
Compare the middle elements of arrays arr1 and arr2, let us call these indices mid1 and mid2 respectively. Let us assume arr1[mid1] k, then clearly the elements after mid2 cannot be the required element. Set the last element of arr2 to be arr2[mid2].
In this way, define a new subproblem with half the size of one of the arrays.
Time Complexity: O(log n + log m)
Auxiliary Space: O(logn + logm)
The second round was based on data structures and puzzles, conducted on skype. He asked me to implement a stack. I implement it using a singly linked list. With the pointer pointing to the end of the linked list. I implemented push, pop operations handling overflow and underflow cases. Initially I was maintaining two pointers but he was not satisfied with it and told me to do it using only one pointer. I implement push and pop functions in O(1). I was asked 5 pirates and 100 gold coins puzzle.
There are 5 pirates, they must decide how to distribute 100 gold coins among them. The pirates have seniority levels, the senior-most is A, then B, then C, then D, and finally the junior-most is E. Rules of distribution are: The most senior pirate proposes a distribution of coins.All pirates vote on whether to accept the distribution.The distribution is approved if at least half of the pirates agree (including the proposer)If the distribution is accepted, the coins are disbursed and the game ends.If not, the proposer is thrown and dies, and the next most senior pirate makes a new proposal to begin the system again.In case of a tie vote, the proposer can have the casting voteRules every pirate follows.Every pirate wants to surviveGiven survival, each pirate wants to maximize the number of gold coins he receives.What is the maximum number of coins that pirate A might get?
The answer is 98 which is not intuitive.
A uses the facts below to get 98.
Consider the situation when A, B, and C die, only D and E are left. E knows that he will not get anything (D is senior and will make a distribution of (100, 0). So E would be fine with anything greater than 0.
Consider the situation when A and B die, C, D, and E are left. D knows that he will not get anything (C will make a distribution of (99, 0, 1)and E will vote in favor of C).
Consider the situation when A dies. B, C, D, and E are left. To survive, B only needs to give 1 coin to D. So distribution is (99, 0, 1, 0)
Similarly, A knows about point 3, so he just needs to give 1 coin to C and 1 coin to E to get them in favor. So distribution is (98, 0, 1, 0, 1).
this round is also ds and algo and oops, dbms, cn



If there are any duplicates in the given array we will count only one of them in the consecutive sequence.
For the given 'ARR' [9,5,4,9,10,10,6].
Output = 3
The longest consecutive sequence is [4,5,6].
Can you solve this in O(N) time and O(N) space complexity?
The idea is to first sort the array and find the longest subarray with consecutive elements.
After sorting the array and removing the multiple occurrences of elements, run a loop and keep a count and max (both initially zero). Run a loop from start to end and if the current element is not equal to the previous (element+1) then set the count to 1 else increase the count. Update max with a maximum of count and max.
This problem can be solved in O(n) time using an Efficient Solution. The idea is to use Hashing. We first insert all elements in a Set. Then check all the possible starts of consecutive subsequences.
Algorithm:
Create an empty hash.
Insert all array elements to hash.
Do following for every element arr[i]
Check if this element is the starting point of a subsequence. To check this, simply look for arr[i] – 1 in the hash, if not found, then this is the first element a subsequence.
If this element is the first element, then count the number of elements in the consecutive starting with this element. Iterate from arr[i] + 1 till the last element that can be found.
If the count is more than the previous longest subsequence found, then update this.
Time complexity: O(nLogn).
Time to sort the array is O(nlogn).
Auxiliary space : O(1).
As no extra space is needed.


The width of each bar is the same and is equal to 1.
Input: ‘n’ = 6, ‘arr’ = [3, 0, 0, 2, 0, 4].
Output: 10
Explanation: Refer to the image for better comprehension:

You don't need to print anything. It has already been taken care of. Just implement the given function.
Approach: The idea is to traverse every array element and find the highest bars on the left and right sides. Take the smaller of two heights. The difference between the smaller height and height of the current element is the amount of water that can be stored in this array element.
Algorithm:
Traverse the array from start to end.
For every element, traverse the array from start to that index and find the maximum height (a) and traverse the array from the current index to end, and find the maximum height (b).
The amount of water that will be stored in this column is min(a,b) – array[i], add this value to the total amount of water stored
Print the total amount of water stored.



Input: arr = [2, 1, 5, 6, 2, 3], k = 2
Output: 11
Explanation:
First painter can paint boards 1 to 3 in 8 units of time and the second painter can paint boards 4-6 in 11 units of time. Thus both painters will paint all the boards in max(8,11) = 11 units of time. It can be shown that all the boards can't be painted in less than 11 units of time.
We can implement the naive solution using recursion with the following optimal substructure property:
Assuming that we already have k-1 partitions in place (using k-2 dividers), we now have to put the k-1 th divider to get k partitions.
How can we do this? We can put the k-1 th divider between the i th and i+1 th element where i = 1 to n. Please note that putting it before the first element is the same as putting it after the last element.
The total cost of this arrangement can be calculated as the maximum of the following:
a) The cost of the last partition: sum(Ai..An), where the k-1 th divider is
before element i.
b) The maximum cost of any partition already formed to the left of the k-1 th divider.
Here a) can be found out using a simple helper function to calculate sum
of elements between two indices in the array. How to find out b) ?
We can observe that b) actually is to place the k-2 separators as fairly as
possible, so it is a subproblem of the given problem.
The fourth round was with CEO and it was on Skype. It was HR round.
Why do you want to join this company?
What was the toughest problem you have faced?

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?