Tip 1 : Solve good quality problems
Tip 2 : Prepare for system design as well
Tip 1 : Make a ATS Free resume
Tip 2 : Highlight relevant skills on resume
Test Environment was good
Let us say we have array 'ARR' =[-1,3,5,-2,4,-9]. The longest sub-array with the positive product is [3,5,-2,4,-9].
The problem can be solved using Dynamic Programming. The idea here is to maintain the count of positive elements and negative elements such that their product is positive. Follow the steps below to solve the problem:
Initialize the variable, say res, to store the length of the longest subarray with the positive product.
Initialize two variables, Pos and Neg, to store the length of the current subarray with the positive and negative products respectively.
Iterate over the array.
If arr[i] = 0: Reset the value of Pos and Neg.
If arr[i] > 0: Increment Pos by 1. If at least one element is present in the subarray with the negative product, then increment Neg by 1.
If arr[i] < 0: Swap Pos and Neg and increment the Neg by 1. If at least one element is present in the subarray with the positive product, then increment Pos also.
Update res=max(res, Pos).
You can’t sell without buying first.
For the given array [ 2, 100, 150, 120],
The maximum profit can be achieved by buying the stock at minute 0 when its price is Rs. 2 and selling it at minute 2 when its price is Rs. 150.
So, the output will be 148.
In the above complete binary tree, all the levels are filled except for the last. In the last level, all the nodes in the last level are as far left as possible.
It was late night. Few subjective questions & coding question was asked in this round.
Explain Polymorphism
What is Method Overloading & Method Overriding
Explain Inheritance
What are Abstract Classes
Explain Pure Virtual Functions.
Let N = 8 and M = 3
The numbers divisible by 3 are 3, 6, 9, …
From these numbers 9 is closest to 8. Thus, the answer is 9.
What is thrashing
What is caching
Explain mutex locks
In this round, few subjective question, 1 design question & one DS question was asked
Design a system, that will help us to store the details of a person, countries he visited & where he stayed in the country & other details.
The values should not get changed by the process in between when we fetch it. This means once stored, it will not change forever (i.e It should be Immutable).
I told him that we can use unordered_map to store person's details. He said that he wanted to see Low Level Design for this.
What are Mutable Objects & Immutable Objects.?
How can you create Immutable objects, so that they don't get changed while processing by CPU?
Give real life scenario for both mutable & Immutable objects.
A subtree of a node X is X, plus every node that is a descendant of X.
Look at the below example to see a Binary Tree pruning.
Input: [1, 1, 1, 0, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
Output: [1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1]
For example, the input for the tree depicted in the below image would be :
1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1
Level 1 :
The root node of the tree is 1
Level 2 :
Left child of 1 = 2
Right child of 1 = 3
Level 3 :
Left child of 2 = 4
Right child of 2 = null (-1)
Left child of 3 = 5
Right child of 3 = 6
Level 4 :
Left child of 4 = null (-1)
Right child of 4 = 7
Left child of 5 = null (-1)
Right child of 5 = null (-1)
Left child of 6 = null (-1)
Right child of 6 = null (-1)
Level 5 :
Left child of 7 = null (-1)
Right child of 7 = null (-1)
The first not-null node (of the previous level) is treated as the parent of the first two nodes of the current level. The second not-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on.
The input ends when all nodes at the last level are null (-1).
The above format was just to provide clarity on how the input is formed for a given tree.
The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
How do you write a single-line comment in C++?