Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.
Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.
This was an online coding round where we had 3 questions to solve under 120 minutes. The questions were of medium to hard difficulty level.



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 :
1) Create two lists or arrays, say, ‘leftMax’ and ‘rightMax’.
2) At every index in the ‘leftMax’ array store the information of the ‘leftMaxHeight’ for every elevation in the map.
3) Similarly, at every index in the ‘rightMax’ array store the information of the ‘rightMaxHeight' for every elevation in the map.
4) Iterate over the elevation map and find the units of water that can be stored at this location by getting the left max height and right max height from the initial arrays that we created.
TC : O(N), where N=total number of elevations in the map.
SC : O(N)



1. Coordinates of the cells are given in 0-based indexing.
2. You can move in 4 directions (Up, Down, Left, Right) from a cell.
3. The length of the path is the number of 1s lying in the path.
4. The source cell is always filled with 1.
1 0 1
1 1 1
1 1 1
For the given binary matrix and source cell(0,0) and destination cell(0,2). Few valid paths consisting of only 1s are
X 0 X X 0 X
X X X X 1 X
1 1 1 X X X
The length of the shortest path is 5.
Approach (Using BFS) :
1) Create an empty queue and enqueue source cell and mark it as visited
2) Declare a ‘STEPS’ variable, to keep track of the length of the path so far
3) Loop in level order till the queue is not empty
3.1) Fetch the front cell from the queue
3.2) If the fetched cell is the destination cell, return ‘STEPS’
3.3) Else for each of the 4 adjacent cells of the current cell, we enqueue each valid cell into the queue and mark them visited.
3.4) Increment ‘STEPS’ by 1 when all the cells in the current level are processed.
4) If all nodes in the queue are processed and the destination cell is not reached, we return -1.
TC : O(N*M) , where ‘N’ and ‘M’ are the number of rows and columns in the Binary Matrix respectively.
SC : O(N*M)


Approach :
1) Given a tree node ROOT, initialise a queue of nodes NODEQUEUE and COUNT by 0.
2) Push ROOT into NODEQUEUE.
3) While NODEQUEUE is not empty do:
3.1) Initialize node TEMP as NODEQUEUE.peek().
3.2) If TEMP.left is not NULL, push TEMP.left to NODEQUEUE.
3.3) If TEMP.right is not NULL, push TEMP.right to NODEQUEUE.
3.4) If TEMP.right and TEMP.left are both NULL, increase COUNT by 1.
4) Return COUNT
TC : O(N), where N=number of nodes in the tree.
SC : O(N)
In this round I was first asked 2 questions related to DSA where I was expected to first explain my approach to the interviewer along with proper complexity analysis and then code the implementation in any of my preferred IDE. This was followed by some questions related to OOPS and C++.



Let the array be [1, 2, 3, 4, 4, 5]. In the given array ‘4’ occurs twice and the number ‘6’ is missing.
Approach 1 :
1) We use a count array to store the frequency.
2) We initialize the count array to zero for all the numbers.
3) Now, iterate through the array and increment the corresponding frequency count of the numbers.
4) Now, we iterate through the count (frequency) array.
5) The number with a frequency equal to zero is the missing number while the number with a frequency equal to two
is the repeating number.
TC : O(N), where N=size of the array
SC : O(N)
Approach 2 :
1) Traverse the array and mark the index corresponding to the current number.
2) While traversing if the index corresponding to the current number has already been marked. Then the current
number is the repeating number in the array.
3) In order to determine the missing number, traverse the array again and look for a positive value.
4) The index corresponding to the positive number gives us the missing number (= index + 1).
TC : O(N), where N=size of the array
SC : O(1)



Given array/list can contain duplicate elements.
(arr[i],arr[j]) and (arr[j],arr[i]) are considered same.
Approach :
1) Create a hashmap/dictionary which will store the count of occurrences of each element and initially it will be empty.
2) Run a loop from i=0 to N-1 and for each i’th element its value is arr[i] and we need to find the number which is equal to Sum - arr[i]. So check if sum-arr[i] is present in the hashmap/dictionary. If it is present, the answer will be increased by the count of occurrence of sum-arr[i] present in the hashmap/dictionary as arr[i] can be paired with all those sum-arr[i] elements present in its left side.
3) Now increase the count of arr[i] in the hashmap/dictionary by 1.
TC : O(N), where N=size of the array
SC : O(N)
Difference between structure and union and what are the pros and cons of both?
Answer :
Structure : Structure is a user-defined data type in C programming language that combines logically related data
items of different data types together.
All the structure elements are stored at contiguous memory locations. Structure type variable can store more than
one data item of varying data types under one name.
Union : Union is a user-defined data type, just like a structure. Union combines objects of different types and sizes
together. The union variable allocates the memory space equal to the space to hold the largest variable of union. It
allows varying types of objects to share the same location.
Key differences b/w Structure and Union :
1) Every member within structure is assigned a unique memory location while in union a memory location is shared
by all the data members.
2) Changing the value of one data member will not affect other data members in structure whereas changing the
value of one data member will change the value of other data members in union.
3) Structure is mainly used for storing various data types while union is mainly used for storing one of the many data
types.
4) In structure, you can retrieve any member at a time on the other hand in union, you can access one member at a
time.
5) Structure supports flexible array while union does not support a flexible array.
Advantages and Disadvantages of using Structure :
Advantages :
1) Structures gather more than one piece of data about the same subject together in the same place.
2) It is helpful when you want to gather the data of similar data types and parameters like first name, last
name, etc.
3) It is very easy to maintain as we can represent the whole record by using a single name.
Disadvantages :
1 )If the complexity of IT project goes beyond the limit, it becomes hard to manage.
2) Change of one data structure in a code necessitates changes at many other places. Therefore, the
changes become hard to track.
3) Structure is slower because it requires storage space for all the data.
Advantages and Disadvantages of using Union :
Advantages :
1) It occupies less memory compared to structure.
2 )When you use union, only the last variable can be directly accessed.
3) Union is used when you have to use the same memory location for two or more data members.
Disadvantages :
1) You can use only one union member at a time.
2) All the union variables cannot be initialized or used with varying values at a time.
3) Union assigns one common storage space for all its members.
Tip : Cover concepts of OOPS properly preferrably in C++ or in Java and for quick revision, the guided path of C++ in
Coding Ninjas is a very good resource. I completed the OS and C++ guided path before my interviews and it helped
me a lot.
How does C++ support Polymorphism?
C++ is an Object-oriented programming language and it supports Polymorphism as well:
Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features like templates, function overloading, and default arguments.
Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual functions. Virtual functions take the shape of the functions based on the type of object in reference and are resolved at runtime.
This round had 3 questions from DSA which I had to code under 60 minutes and then the interviewer asked some questions from Operating Systems and Android as I did a project in Mobile App Development.



For the given binary tree [1, 2, 3, -1, -1, 4, 5, -1, -1, -1, -1]
1
/ \
2 3
/ \
4 5
Output: 1 3 2 4 5
Approach :
1) We will maintain two stacks, one for each direction i.e. leftToRight and rightToleft.
2) We will do a level order traversal of the given binary tree and push nodes of each level onto one of the stack according to the current direction of traversal.
3) After we’ve pushed all nodes of a level onto one stack, we’ll start popping those nodes. While popping the nodes we will push their children (if any) onto our other direction stack, so that the next level be traversed in reverse order.
TC : O(N), where ‘N’ is the number of nodes in the binary tree.
SC : O(N)



1. Constructor:
It initializes the data members(queues) as required.
2. push(data) :
This function should take one argument of type integer. It pushes the element into the stack and returns nothing.
3. pop() :
It pops the element from the top of the stack and, in turn, returns the element being popped or deleted. In case the stack is empty, it returns -1.
4. top :
It returns the element being kept at the top of the stack. In case the stack is empty, it returns -1.
5. size() :
It returns the size of the stack at any given instance of time.
6. isEmpty() :
It returns a boolean value indicating whether the stack is empty or not.
Query-1(Denoted by an integer 1): Pushes an integer data to the stack. (push function)
Query-2(Denoted by an integer 2): Pops the data kept at the top of the stack and returns it to the caller. (pop function)
Query-3(Denoted by an integer 3): Fetches and returns the data being kept at the top of the stack but doesn't remove it, unlike the pop function. (top function)
Query-4(Denoted by an integer 4): Returns the current size of the stack. (size function)
Query-5(Denoted by an integer 5): Returns a boolean value denoting whether the stack is empty or not. (isEmpty function)
Operations:
1 5
1 10
2
3
4
Enqueue operation 1 5: We insert 5 at the back of the queue.
Queue: [5]
Enqueue operation 1 10: We insert 10 at the back of the queue.
Queue: [5, 10]
Dequeue operation 2: We remove the element from the front of the queue, which is 5, and print it.
Output: 5
Queue: [10]
Peek operation 3: We return the element present at the front of the queue, which is 10, without removing it.
Output: 10
Queue: [10]
IsEmpty operation 4: We check if the queue is empty.
Output: False
Queue: [10]
Approach : A stack can be implemented using two queues. Let stack to be implemented be ‘s’ and queues used to implement be ‘q1’ and ‘q2’. Stack ‘s’ can be implemented in two ways :
Method 1 (push - O(1) , pop - O(n) ) :
1) push(s, x) operation :
i) Enqueue x to q1 (assuming size of q1 is unlimited).
2) pop(s) operation :
i) One by one dequeue everything except the last element from q1 and enqueue to q2.
ii) Dequeue the last item of q1, the dequeued item is result, store it.
iii) Swap the names of q1 and q2
iv) Return the item stored in step 2.
TC : push(s,x) -> O(1)
pop() -> O(n)
Method 2 (push - O(n) , pop - O(1) ) :
1) push(s, x) operation :
i) Enqueue x to q2
ii) One by one dequeue everything from q1 and enqueue to q2.
iii) Swap the names of q1 and q2
2) pop(s) operation :
i) Dequeue an item from q1 and return it.
TC : push(s,x) -> O(n)
pop() -> O(1)



Below is the example showing the input tree and its sum tree.

Approach :
1) Traverse a given binary tree.
2) While traversing the given binary tree, store the old value of the current node, recursively call for left and right subtrees.
3) Now change the value of the current node as the sum of the values returned by the recursive calls of left and right subtrees.
4) Finally, return the sum of the new value and value (which is the sum of values in the subtree rooted with this node).
TC : O(N), where ‘N’ is the number of nodes in the given binary tree.
SC : O(N)
What is meant by Multitasking and Multithreading in OS?
Answer :
Multitasking : It refers to the process in which a CPU happens to execute multiple tasks at any given time. CPU
switching occurs very often when multitasking between various tasks. This way, the users get to collaborate with
every program together at the same time. Since it involves rapid CPU switching, it requires some time. It is because
switching from one user to another might need some resources. The processes in multi-tasking, unlike multi-
threading, share separate resources and memories.
Multithreading : It is a system that creates many threads out of a single process to increase the overall power and
working capacity of a computer. In the process of multi-threading, we use a CPU for executing many threads out of a
single process at any given time. Also, the process of creation depends entirely on the cost. The process of
multithreading, unlike multitasking, makes use of the very same resources and memory for processing the execution.
What is Android?
Android is an open-sourced operating system that is used on mobile devices, such as mobiles and tablets. The Android application executes within its own process and its own instance of Dalvik Virtual Machine(DVM) or Android RunTime(ART).
This was about 30 minutes long interview. First, she asked introduction, after that she was very interested in my internship that I did in summer and about my interests. She asked few common questions on that.
Tip : Please ask questions at the end of session when they ask you to do so. In the end, she asked if I had any
questions for her and I asked how is life working in Samsung, how long she was working and in which domain. The interview went well in the end.

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?