Flipkart limited interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

Flipkart limited
upvote
share-icon
3 rounds | 8 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 Months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

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.

Application process
Where: Campus
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

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.

Interview rounds

01
Round
Medium
Face to Face
Duration60 Minutes
Interview date9 May 2015
Coding problem3

This was a typical DS/Algo where I was asked to solve two questions related to Binary Trees and write the pseudo code for both of them followed by some theoretical questions related to Operating Systems.

1. K-th largest Number BST

Easy
10m average time
90% success
0/40
Asked in companies
AmazonHSBCFreshworks

You are given a binary search tree of integers with 'N' nodes. Your task is to return the K-th largest element of this BST.

If there is no K-th largest element in the BST, return -1.

A binary search tree (BST) is a binary tree data structure which has the following properties.

• The left subtree of a node contains only nodes with data less than the node’s data.
• The right subtree of a node contains only nodes with data greater than the node’s data.
• Both the left and right subtrees must also be binary search trees.
Problem approach

Approach :
1) The idea is to do reverse inorder traversal of BST. Keep a count of nodes visited.
2) The reverse inorder traversal traverses all nodes in decreasing order, i.e, visit the right node then centre then left and continue traversing the nodes recursively.
3) While doing the traversal, keep track of the count of nodes visited so far.
4) When the count becomes equal to n, stop the traversal and print the key.

//Pseudo Code : 

void nthLargestInBST(TreeNode*root , int n, int&cnt)
{
if(!root || cnt>=n)
return;

cnt++;
nthLargestInBST(root->right,n,cnt);
if(cnt==n)
{
cout<<"Nth largest element in BST = "}

TC : O(h+n) where h=height of the tree and n is given
SC : O(h)

Try solving now

2. Is Height Balanced Binary Tree

Moderate
15m average time
85% success
0/80
Asked in companies
AmazonAdobeVisa

You are given the root node of a binary tree.


Return 'true' if it is a height balanced binary tree.


Note:
Height of a tree is the maximum number of nodes in a path from the node to the leaf node.

An empty tree is a height-balanced tree. A non-empty binary tree is a height-balanced binary tree if
1. The left subtree of a binary tree is already the height-balanced tree.
2. The right subtree of a binary tree is also the height-balanced tree.
3. The difference between heights of left subtree and right subtree must not more than ‘1’.


Example:

Input: Consider the binary tree given below:

alt text

Output: 'true'

Explanation:
Consider subtree at Node ( 7 ) 
Left subtree height is ‘0’ and right subtree height is ‘0’, the absolute height difference is ‘0-0 = 0’ and ‘0’ is not more than ‘1’ so subtree at Node ( 7 ) is a height-balanced binary tree. 
Same for subtrees at Nodes ( 5, 6 ). 

Consider subtree at Node ( 4 ) 
Left subtree height is ‘1’ and right subtree height is ‘0’, the absolute height difference is ‘1-0 = 1’ and ‘1’ is not more than ‘1’ so subtree at Node ( 4 ) is a height-balanced binary tree.
Same for subtree at Node ( 3)

Consider subtree at Node ( 2 ) 
Left subtree height is ‘2’ and right subtree height is ‘1’, the absolute height difference is ‘2-1 = 1’ and ‘1’ is not more than ‘1’ so subtree at Node ( 2 ) is a height-balanced binary tree.

Consider subtree at Node ( 1 ) 
Left subtree height is ‘3’ and right subtree height is ‘2’, the absolute height difference is ‘3-2 = 1’ and ‘1’ is not more than ‘1’ so subtree at Node ( 1 ) is a height-balanced binary tree.

Because the root node ( 1 ) is a height-balanced binary tree, so the complete tree is height-balanced.


Problem approach

Approach 1 :
1) To check if a tree is height-balanced, get the height of left and right subtrees. 
2) Return true if difference between heights is not more than 1 and left and right subtrees are balanced, otherwise return false.

//Pseudo Code
int height(TreeNode*root)
{
if(!root)
return 0;
return 1+max(height(root->left) , height(root->right));
}

bool isBalanced(TreeNode*root)
{
if(!root)
return true;
int leftHt=height(root->left);
int rightHt=height(root->right);
if(isBalanced(root->left) and isBalanced(root->right) and abs(leftHt-rightHt)<=1)
return true;
return false;
}

TC : O(N^2) where N=number of nodes in the Binary Tree
SC : O(N)


Approach 2 (Time Efficient ) :
1) Above implementation can be optimized by calculating the height in the same recursion rather than calling a height() function separately .
2) Then check if the answer is already false or not if it is already false, then simply return 0 .
3) Else return the height of the node . 

//Pseudo Code : 

bool ans;

int checkBalance(TreeNode* root)
{
if(!root)
return 0;
if(!ans) // if Answer is already False then return it.
return 0;
int leftSubTree = checkBalance(root->left);
int rightSubTree = checkBalance(root->right);
if(abs(leftSubTree-rightSubTree) > 1)
{
ans = false;
}

return 1 + max(leftSubTree, rightSubTree);
}

bool isBalanced(TreeNode* root){
ans = true;
int temp = checkBalance(root);
return ans;
}

TC : O(N) where N=number of nodes in the tree
SC : O(N)

Try solving now

3. OS Question

Explain Zombie Process and Orphan Process .

Problem approach

Answer : 

Zombie Process : A process which has finished the execution but still has entry in the process table to report to its parent process is known as a zombie process. A child process always first becomes a zombie before being removed from the process table. The parent process reads the exit status of the child process which reaps off the child process entry from the process table.

Orphan Process : A process whose parent process no more exists i.e. either finished or terminated without waiting for its child process to terminate is called an orphan process.
In the following code, parent finishes execution and exits while the child process is still executing and is called an orphan process now.
However, the orphan process is soon adopted by init process, once its parent process dies.

02
Round
Medium
Face to Face
Duration60 Minutes
Interview date9 May 2015
Coding problem3

This was also a Data Structures and Algorithm round where I was asked to solve 3 medium to hard level problems along with their pseudo code within 60 minutes .

1. Longest Substring Without Repeating Characters

Moderate
20m average time
80% success
0/80
Asked in companies
AmazonInfo Edge India (Naukri.com)Oracle

Given a string 'S' of length 'L', return the length of the longest substring without repeating characters.

Example:

Suppose given input is "abacb", then the length of the longest substring without repeating characters will be 3 ("acb").
Problem approach

Approach : I solved it using 2-pointers and keeping a track of the frequency of the elements encountered in a freq array of size 26

Steps :
1) Initiliase a freq array of size 26 where a=0, b=1 ...,z=25 .
2) Let s be our string and n = s.size()
3) Do , freq[s[0]]++;
4) Keep 2 pointers start and end where initially start=0 and end=1 also maintain a answer variable ans where initially ans=0
5) Now run a loop till end=1 and startfreq(26,0);
freq[s[0]-'a']++;
int start=0 , end=1 ;
int ans=1;
while(end=1 and start {
freq[s[start]-'a']--;
start++;
}
freq[s[end]-'a']++;
}
ans=max(ans,end-start+1);
end++;
}
return ans;
}

Try solving now

2. Search In Rotated Sorted Array

Moderate
30m average time
65% success
0/80
Asked in companies
InformaticaDelhiveryGoldman Sachs

Aahad and Harshit always have fun by solving problems. Harshit took a sorted array consisting of distinct integers and rotated it clockwise by an unknown amount. For example, he took a sorted array = [1, 2, 3, 4, 5] and if he rotates it by 2, then the array becomes: [4, 5, 1, 2, 3].

After rotating a sorted array, Aahad needs to answer Q queries asked by Harshit, each of them is described by one integer Q[i]. which Harshit wanted him to search in the array. For each query, if he found it, he had to shout the index of the number, otherwise, he had to shout -1.

For each query, you have to complete the given method where 'key' denotes Q[i]. If the key exists in the array, return the index of the 'key', otherwise, return -1.

Note:

Can you solve each query in O(logN) ?
Problem approach

This was a preety standard Binary Search Question and I had solved this question before on platforms like LeetCode and CodeStudio . I was asked this question to test my implementation skills and how well do I handle Edge Cases .

Approach :
1) The idea is to find the pivot point, divide the array in two sub-arrays and perform binary search.
2) The main idea for finding pivot is – for a sorted (in increasing order) and pivoted array, pivot element is the only element for which next element to it is smaller than it.
3) Using the above statement and binary search pivot can be found.
4) After the pivot is found out divide the array in two sub-arrays.
5) Now the individual sub – arrays are sorted so the element can be searched using Binary Search.

TC : O(Log(N))
SC : O(1)

Try solving now

3. Count all sub-arrays having sum divisible by k

Moderate
15m average time
85% success
0/80
Asked in companies
MicrosoftProtiumIntuit

Given an array ‘ARR’ and an integer ‘K’, your task is to find all the count of all sub-arrays whose sum is divisible by the given integer ‘K’.

Note:
If there exists no subarray in the given sequence whose sum is divisible by ‘K’ then simply return ‘0’.
Example:
Suppose the given array is ‘ARR’ = { 5, 0, 2, 3, 1} and ‘K = 5’.
As we can see in below image, there are a total of 6 subarrays that have the total sum divisible by ‘K’
So we return the integer 6.

subsequence

Problem approach

Approach 1 (Naive Solution ) : 
One by one calculate sum of all sub-arrays possible and check divisible by K. 

TC : O(N^2)
SC : O(1)

Approach 2 (Efficient Solution) :

Observe : Let sum(i,j)=subarray sum from arr[i] to arr[j] (both inclusive) (arr[i]+arr[i+1]...+arr[j])

Now for sum(i,j) to be divisible by k , th following condition must hold :

sum(0,j)%k=sum(0,i-1)%k

Keeping the above points in mind , let's design an efficient algo for this problem : 

Algorithm :

1) Make an auxiliary array of size k as Mod[k] . This array holds the count of each remainder we are getting after dividing cumulative sum till any index in arr[].

2) Now start calculating cumulative sum and simultaneously take it’s mod with K, whichever remainder we get increment count by 1 for remainder as index in Mod[] auxiliary array. 

3) Sub-array by each pair of positions with same value of ( cumSum % k) constitute a continuous range whose sum is divisible by K.

4) Now traverse Mod[] auxiliary array, for any Mod[i] > 1 we can choose any two pair of indices for sub-array by (Mod[i]*(Mod[i] – 1))/2 number of ways . 

5) Do the same for all remainders < k and sum up the result that will be the number all possible sub-arrays divisible by K.

//Pseudo Code :

int subarraysDivByK(vector& arr, int k) 
{
int n=arr.size();
vectormod(k,0); 
int cumu=0;
for(int i=0; i1)
ans+=(mod[i]*(mod[i]-1)/2);
}
return ans+mod[0];

}

TC : O(N) where N=size of the array
SC : O(k)

Try solving now
03
Round
Medium
Face to Face
Duration50 Minutes
Interview date9 May 2015
Coding problem2

In this round , I was asked to code a simple question related to BST . After that I was asked the internal implementation of a Hash Map where I was supposed to design a Hash Map using any of the Hashing Algorithms that I know . This was preety challenging for me but I got to learn so much from it.

1. Ceil from BST

Easy
15m average time
85% success
0/40
Asked in companies
SamsungViacom18VMware Inc

Ninja is given a binary search tree and an integer. Now he is given a particular key in the tree and returns its ceil value. Can you help Ninja solve the problem?

Note:
Ceil of an integer is the closest integer greater than or equal to a given number.
For example:
arr[] = {1, 2, 5, 7, 8, 9}, key = 3.
The closest integer greater than 3 in the given array is 5. So, its ceil value in the given array is 5.
Problem approach

Approach :
The idea is to follow the recursive approach for solving the problem i.e. start searching for the element from the root. 

1) If there is a leaf node having a value less than N, then element doesn’t exist and return -1.
2) Otherwise, if node’s value is greater than or equal to N and left child is NULL or less than N then return the node value.
3) Else if node’s value is less than N, then search for the element in the right subtree.
4) Else search for the element in the left subtree by calling the function recursively according to the left or right value.

TC : O(h) where h=Height of the Binary Tree
SC : O(h)

Try solving now

2. Implementation: HashMap

Easy
30m average time
90% success
0/40
Asked in companies
eBayAmazonUber

Design a data structure that stores a mapping of a key to a given value and supports the following operations in constant time.

1. INSERT(key, value): Inserts an integer value to the data structure against a string type key if not already present. If already present, it updates the value of the key with the new one. This function will not return anything.

2. DELETE(key): Removes the key from the data structure if present. It doesn't return anything.

3. SEARCH(key): It searches for the key in the data structure. In case it is present, return true. Otherwise, return false.

4. GET(key): It returns the integer value stored against the given key. If the key is not present, return -1. 

5. GET_SIZE(): It returns an integer value denoting the size of the data structure. 

6. IS_EMPTY(): It returns a boolean value, denoting whether the data structure is empty or not. 
Note :
1. Key is always a string value.
2. Value can never be -1.
Operations Performed :
First(Denoted by integer value 1):  Insertion to the Data Structure. It is done in a pair of (key, value).

Second(Denoted by integer value 2):  Deletion of a key from the Data Structure.

Third(Denoted by integer value 3): Search a given key in the Data Structure.

Fourth(Denoted by integer value 4): Retrieve the value for a given key from the Data Structure.

Fifth(Denoted by integer value 5): Retrieve the size of the Data Structure.

Sixth(Denoted by integer value 6): Retrieve whether the Data Structure is empty or not.
Problem approach

Approach :

Some key points about a Hash Map : 

1) HashMap is the data structure used to store key-value pairs, where the average retrieval time for get() and insert() operations is constant i.e. O(1).

2) Hashmap uses the array of Singly Linked List internally.

3) The array is called the buckets and at every bucket(i-th index of the array) holds a pointer to head of the Singly Linked List.

4) Every Linked List Node has fields called the ‘KEY’, ‘VALUE’ and certainly the pointer to the next node.

5) For every entry of a key, we try to generate a ‘unique value’ pointing to the bucket where it can be stored. It can also be said that we try to find an index against every key that needs to be inserted or updated in the array/buckets.

6) If we know which bucket to look at, then we can make the operations, ‘INSERT’ , and ‘GET’ in the constant time since fetching a value or updating a value at a known index in an array is a constant time operation.

7) To calculate the index against every key that needs to be inserted we use hashing algorithms. The values thus computed are called Hash Values. This hash value serves as the location or index of the bucket.


Functions to be implemented:

1. INSERT(VALUE) :

We will first compute the hash value or location in the buckets where the key needs to be inserted using any of the hashing algorithms available. 

In case the location doesn’t have a list already, we make it as the head or if the location already contains a list(case of collision) we insert the new key at the head.

To make sure that every insert operation happens in constant time, we keep a threshold of 0.7(less than 1) over the load factor. If the load factor exceeds the threshold value, we run a rehash function. 

loadFactor = (size * 1.0) / buckets.size()

The load factor is defined to be the total load that is being put on the buckets. We try to keep it less than or equal to 0.7 to maintain the operations performed are constant. 

RE_HASH(): This function basically increases the total bucket size by either a factor of multiple of 2 or by the power of 2 and every KEY present is inserted into the updated buckets(you may read more about it on the internet).



2. DELETE(VALUE):

It works in a similar way we discussed above for the insert function. 



3. SEARCH(KEY):

Generate the hash value against the key to be searched and get the bucket corresponding to the key by taking modulo with the total bucket size.



TC : O(1) , All the functions take constant time. Hence, the overall Time Complexity is O(1).
SC : O(N) , where ‘N’ is the number of elements in the HashMap.

Try solving now

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

How do you remove whitespace from the start of a string?

Choose another skill to practice
Similar interview experiences
SDE - 1
3 rounds | 10 problems
Interviewed by Flipkart limited
2633 views
0 comments
0 upvotes
SDE - 1
3 rounds | 7 problems
Interviewed by Flipkart limited
1188 views
0 comments
0 upvotes
SDE - 1
3 rounds | 3 problems
Interviewed by Flipkart limited
1718 views
0 comments
0 upvotes
SDE - 1
3 rounds | 4 problems
Interviewed by Flipkart limited
2197 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
115096 views
24 comments
0 upvotes
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
58237 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35146 views
7 comments
0 upvotes