Professional Documents
Culture Documents
I was recently interviewed for SDE-II in Flipkart. A lot of emphasis was on designing
and geeksforgeeks has been a lot of help. These are my interview questions:
Round 1 : Machine Round (2-3 hours)
Company hierarchy/bonus question.
Write down code in any language for a simple employee hierarchy which has 3
types of employees.
1. CEO
2. Manager
3. employee
Where an employee can have only 1 mgr, and a mgr has 1+ employees.
We were asked to input employee details(name ,id, salary,rating etc) in any order
(employees might be input before his manager), create the hierarchy and
implement these functionality:
1. Print hierarchy given any employee/mgr/ceo (used an n-ary tree + hash table)
2. Given a bonus and performance rating of each employee divide it to the lowest
level employees(in the hierarchy ) in the ratio of their rating. i.e 100 divided among
2:3 is 40 and 60. and print the bonus of each ( simple recursive solution)
3. Top 10 employees with ratio of bonus:salary (used maxheap)
Had a discussion on the solution with various variants and edge/faulty cases.
Round 2 : Problem Solving Round (1.5 hours)
1. A solution was required to make a fantasy league with some budget allocated.
Players will have some score/rating and the cost of player. Maximum score was to
be achieved with eleven players.
Had a lot of discussion on various approaches like backtracking, modified knapsack
etc.
2. A set of tasks is given of which some are dependent tasks. Solution was required
to enable parallel processing of the tasks. (Used topological sort)
Round 3 : Designing Round (1 1.5 hours)
A library for game 2048 was to be designed. The game can have constraints/
variations which shall be defined by the game designer. The variations can be
adding same numbers or adding Fibonacci numbers etc. APIs were to be exposed
to the game designer.
Round 4 : Manager Round (45mins)
A lot of behavioral questions. Discussion about the product and the work I do.
Challenges faced etc.
Test Case #00: We have to replace at least three characters from any of the string
to make both of strings anagram. Here, a = aaa and b = bbb. One possible
solution is to replace all character a in string a with character b.
Test Case #01: Either replace a with b, which will generate bb. Or replace b
with a to generate aa. Both of the solution are valid.
Test Case #02: It is not possible for two strings of unequal length to be anagram for
each other.
Test Case #03: We have to replace both the characters of any string to make it
anagram of other one.
2) Five Years from now
3) Expectations from Flipkart?
4) Hobbies and weekend plans and location related questions
5) Any questions for me?
Keep up the good work guys.
This was the most exciting round. Problem was to do 3 operations on very large
numbers.
1. Addition 2. Subtraction 3. Multiplication
Input can be positive or negative. In this round, focus was on Design and Coding
Skills.
I was given 1 hr 30 mins to code for the problem. I completed in around 1hr 15
mins. Then he asked me extend my code for decimal numbers as well. I told him
the approach. Then he asked me how will i do the division as well.
Problem Solving Round In this round he started with the discussion of Machine round problem. Then he
asked me a simple problem. Find the first occurrence of a digit(1-9) other than zero
in a stream of integers in less than o(n). Given i cant have the access to the
memory location where stream is written.
He basically wanted to know how i think and how many approaches i can think of,
and whether i can challenge him or not that its not possible. and yes i did.
Then he asked a stock span problem. Given stock prices in an array. Find the
buying and selling time so that profit earned is maximum.
Hiring Manager round
He asked me some behavioral questions.
Why do you want to join Flipkart. Then What would you do if something goes wrong
on production, and you are unable to find the bug, etc.
Them he discussed the projects i had done in my previous company.
Example:
For the graph in diagram, A dependencies: C,D i.e. 2
B dependencies: D i.e. 1
C dependencies: D i.e. 1
And D depends on none.
Hence answer=0+1+1+2=4.
Given a N find out the number of numbers possible of given length. It was asked to
write the code.
Example:
For N=2
Possible numbers: 00,08 11,12,14 22,21,23,25 and so on. We have to print the
count of such numbers.
I solved it using DP in first attempt. He was quite impressed as I took very less time
to think of the exact solution.
Question 2: Given a undirected graph with following special points:
1) Every node has at most 3 links.
2) Node with a single link is a leaf node.
3) Nodes are numbered from 1 to N.
(Think how is it different from a 3-ary Tree, See bold text
)
We do the following operation on the given graph: Among all the current leaf nodes
we search for the node with minimum node value, delete it and print its parent. We
do this operation until only two nodes are left in the graph.
If your are given N and an array having the printed values from the operation, you
have to generate the graph back. Exact implementation was asked to write.
Example:
N=8
ar[]= {4,3,6,6,5,4}
Output should be adjacency matrix for the following graph.
Round 4 : Technical + HR
Time : 1 Hour
1) Introduction.
2) Asked everything about my project every minute detail, even I was asked to write
code for few sections of my code i.e. how I implemented those features.
3) Asked few questions on teamwork that how would I handle particular situations.
4) Strengths and weaknesses.
5) Tell me about one thing that you have done in college and proud of be it in
academics or in any field.
6) Best and worst classmate till now and Why !!
With this as the final interview my long journey of Interviews ended
. Wish you
all, all the very best hope this would help
Following are screenshots of round 1 online coding questions.
weak.(I mean if such a tough question is in first round they gotta compensate
somewhere else).
2- Given a network of roads connecting cities and capacity of each road(same for
all roads)as well as their cost of repair(unique for each road) we are given number
of buses(n) running between pair of cities using shortest path only. (Capacity of
road= No of buses allowed on that road).
Unsafe roads are road where no of buses on the road > Capacity of the road.
Now given n we have to minimize the overall cost of all unsafe roads.
Pretty tough from what I recall I understood that we have to calculated the
maximum number of disjoint shortest paths so as to minimize the answer.(My
solution only passed one test case).
Round 1(F-2-F)
I was asked variety of questions ranging from strings to dp to graphs.
1- Given a corrupted string i.e its original string with just the spaces at wrong
places, Construct the original string .We are given a dictionary of words.
Ex:string : Com put erengineering
original string: Computer Engineering
I gave the interviewer a recursive solution. The I was asked to code it. After that I
was asked whether I could optimize the code further. I could not.
2- Given a lane where there are various houses each containing a fixed amount of
gold. Now a robber has to rob the houses such that when he robs a house the
adjacent one cannot be robbed.Calculate the maximum amount of gold collected by
him.(Classic Dp question).
3- Given 1000 elephant ,none of whom exact heights are known, there are
statements given which will be of two forms
3.i-E_i is taller than E_j
OR
3.ii-E_i is smaller than E_j
all the values int the visited array is marked we will have the final topological sorted
order of the DAG in the stack.
5- Given a pond where all the stones are lined at a distance of one unit (C in each
row and there are R such rows), each stone has a special value which denotes the
length of the jump the frog can make i.e if frog is on stone (x,y) and value is k then
frog can jump to (x+dx,y+dy) where dx+dy=k and frog doesnt leave the
bounds.Find the min number of jumps to reach the stone at (R,C).
Visualized it in from of a matrix.Did it using DP ..In case you are wondering, for
a frog at cel (x,y) run two loops of dx and dy where net dx+dy=k and do dp[x+dx][y
+dy]=min(dp[x][y]+1,dp[x+dx][y+dy]).
Answer would be in dp[R][C].
Then I was asked to bactrack the path which was quite easy as for dp[x][y] subtract
1 from it and look for the resulting value in cells (i,j) where i<=x and j<=y . Repeat
this process till (0,0) is reached.
This conclued my first round. One or two more questions were also asked but I
cannot remember them correctly.
ROUND 2(F-2-F)
Technical + HR
1- Implement LRU and LFU page replacement policy using Data structures.
Had already encountered the question while preparing for Amazon.
I did it using Doubly Ended queue and a hashmap(Map or BST does not matter as
both have same complexity for retrieval and insertion of data).
2- Given a normal die and a blank die. Fill in the blank die such that probability of
sum of the number from both die is same for all the resulting sum and sum has a
range from 1 to 12.
After a hit and trial I realized the number on blank die would be repeated to given a
even probability distribution.
Min element required on blank die = 0
Max element required on blank die = 6.
mark 3 sides with 0 and three with 6 .
Due to the fact that the probability of occurrence of 0 and 6 on the blank die is
same and equal to 0.5 ,
P(Each sum)=1/2*P(i)=1/12 for each number.
Now taking 1/12 in the start then deriving the solution should have been easy but
due to the tiring day and worse weather my mind took the backdoor method.
Some HR related questions to minor projects done in the college and questions
related to my experience with flipkart as a customer.
ROUND 3(BONUS ROUND)
Four of us who got selected after the second round were called in for a GD round
where they told us that they desired to take only two of us.
We were baffled by the claim.
They told us that they wanted a group discussion on the topic WHY SHOULD
FLIPKART HIRE YOU??
We went on for 10 minutes trying to butter them with advantages of flipkart and God
knows what.
Then we were given our results on a chit.
After opening the chit we realized that it was just a prank.
WTF!!Welcome to flipkart
E.g SSSNEEEW
output EESS
2. A sender will send a binary string to a receiver meanwhile he encrypt the digits.
You are given a encrypted form of string. Now, the receiver needs to decode the
string, and while decoding there were 2 approaches.
First, receiver will start with first character as 0; S[0] = 0, P[1] = S[1] + S[0], P[2] =
S[2] + S[1] + S[0] and so on.
Second, Receiver will start with first character as 1; S[0] = 1, P[1] = S[1] + S[0], P[2]
= S[2] + S[1] + S[0] and so on.
You need to print both the strings, after evaluation from both first and second
technique. Uf any string will contain other that binary numbers you need to print
NONE.
Input1; 0123210
Output: 0111000
NONE
explanation for NONE S[0] = 1, P[1] = S[1] + S[0] so S[1] = 0
P[2] = s[2] + S[1] + S[0] , S[2] = 1
P[3] = S[3] + S[2] + S[1], S[3] = 2, not a binary character so NONE
Machine Coding Round (on Interview Street)
There was only one question, time limit 45mins
Q1. Word Wrap problem with few conditions, even i didnt remember much
conditions here are some conditions.
i) there can be maximum of X characters in a single line.
ii) there can be maximum of Y number of spaces in the end of the each single line.
iii) if a string length is big enough, so that it cannot be printed in single line, use - in
the end of the line and print string further in the different line.
also there should not be consecutively in the end, if the string contains already -
in the end dont put - character.
E.g. flip-kart and if x = 5 so it should be ->
flipkart
iv) the string should not start with these characters(. , , )
v) the cost value should be minimum, there can not be multiple answer for a single
string.
Eg. This is a flipkart online programming test.
x = 10 Y = 3
Output
This is a
flipkart
online programming
test.
First Technical Interview (F2F)They asked me about myself, so i gave my brief intro to them(there were 2 people
who were taking the interview)
and then they asked me about, what coding practices you used to do.As i dont do
much coding online so i gave told them truely that only Codeforce and Spoj
After that they started my interview, that what is the approach that you had used in
the Machine Coding Round and how you implemented and why you uses this type
of technique.
My approach was Greedy.
Further they asked me what Data Structure you Know, how you use it some basic
questions.
Later they asked me to print vertical nodes together in the binary tree, he asked me
why you used Recursion in the solution.
After that they asked me a question, which was
you are given an array(say C) of characters and an array(say M) which contains the
indexes of the array of characters.
We started moving elements of array(C) according to the position of indexes given
in the array(M).
e.g. array A a b c d e f g
array M 1 4 3 5 0 2 6
so array A will change in first to e a f c b d g
again applying same b e d f a c g
again applying a b c d e f g
so after 3 times we got the same sequence of characters.
He wants minimum number of times modification on the array (A) so that the we will
again reach to the initial order.
I gave him first recursive solution, then he says optimize it and after that i gave him
O(n) solution; the logic for the problem came to me from Inplace Transpose of
Matrix
the question is like -> http://www.codechef.com/JULY14/problems/SGARDEN/
After this he asked me a question on Next Greater Element, he wants how many
ways i can handle this question.
I told him 3 approaches- 1.O(n^2) 2.O(nlogn) 3.O(n)
He asked me about AVL tree, how you will implement it and then said you have final
interview in early morning
Technical + HR interview(F2F)
In this round, first they asked me about myself while studying My Resume
So they started asking some questions on LINUX like what is gdm but i said sir
didnt know much about linux.
further they asked me how to debug the code, and what is segmentation fault,
memory leak and how you will find the segmentation fault in 5000lines of code.
after that they asked me about my projects, why this project how you did it they
grilled me in every step.. why this why not this and all..
after that he wants some optimization to be performed on the project.
After this they asked me some questions on stack while putting pressure of time
that you have 2mins for this question.
============================
1. Create an employee database structure in which Employee has
id,name,manager. Three functionalities required were
a) Given any id return all the employee details
b) Given any name(or id) list all the subordinates of the given employee.
c) Given a name search with prefix search property.
45 minutes of time was given and running code was asked. Interviewer first asked
the approach and then after coding he reviewed the code thoroughly.
F2F-R2 Data Structure and Algorithm
====================================
1. Given a list of words and a 2D matrix(of characters) find all the valid
words(present in the given list) which are possible inside the given matrix.
Words can be formed in all 8 directions from a given cell.
First discussion about approach and then implementation of the logic.
2. Given a binary tree serialize the tree such that it can be retrieved in the same
form again.
3. Given a double linked list with one pointer pointing to the next node and the other
pointer to any arbitrary node in the list, duplicate the given linked list.
F2F-R3 Hiring Manager
======================
1. Introduction about the organization and the work being done.
2. My introduction and the work done by me.
3. Asked some of the new ideas ( wow!!!!! features ) which can be implemented in
the smart phone.
4. Few other general questions.
F2F-R4 Design Round
====================
1. Design the Tic-Toe game for a smart phone. Discussion about the class
diagrams, structure of the code, code flow, abstraction of code and functionalities.
2. Interviewer asked the approach to implement the above in android.
3. Various android questions.
F2F-R5 Hiring Manger + Reporting Manager
=========================================
Hiring manager was on leave so this happened after a gap of one month after R4.
1. Introduction about work.
2. I asked various questions about work and my role.
3. Design a mobile cab booking application (just screens and functionalities) on
board. Asked questions about the things which I missed during the design.
And what all requirements are needed to before the application goes in
development phase.
Response was positive from the recruiter side.
1. Find all the Node at the distance K from a given node in a Binary tree. Print them
in any order.
2. Design a LRU cache.
Telephone screening rounds
1. Given two sorted linked lists. You start with a one of the two lists and then move
till the end. You may switch to the other list only at the point of intersection (which
mean the two node with the same value in different lists.) You have to find the path
of maximum sum
Eg
1->3->30->90->120->240->511
0->3->12->32->90->125->240->249
You can switch at 3 90 or 240 so the max sum paths is
1->3->12->32->90->125->240->511
2. Design a contact list for a cell phone which can add & search really quick and is
scalable.
Machine coding round
1. Write a program which should create a parse tree, find invalid query and do
some optimizations.
Input: fist line contains the list of columns. There will be subsequent lines which will
contain the query as follows.
EMP_ID, EMP_NAME, EMP_DEPT, EMP_AGE
SELECT EMP_ID,EMP_NAME where EMP_ID>5 AND EMP_NAME=robert
SELECT EMP_AGE WHERE (EMP_NAME=robert AND EMP_ID=5) AND
(EMP_ID=32) OR (EMP_ID= 32)
ONSITE INTERVIEWs
1. Design a Synchronized Message broker queues. How will you handle various
situations like one queue is down, automatic failover, active master selection,
handling acked and unackedmessages.
2. Design a site like book my show. It was an open ended question so I
concentrated on inventory management. List all entities, classes objects modules
and their interactions.
3. Design a secure Card storage system. Again open ended but the concentration
was on encryption and decryption
4. HR round. What are your strength and weaknesses, what did you do that made
you happy. What was your best contribution till date.
5. Design a Traffic signal . List all entities and classes involved. How will you handle
pedestrian crossings etc.
6. Design a game of tic tac toe, handling winning situation etc. NXN, multiplayer,
multiplayer with synchronization, Disaster recovery, data analytics, SWOT of each
approach.
1. Dont remember the questions, but they were of medium level, not tough as
such.
2. Basic knowledge will help you in clearing that round
1st Telephonic
1. Solve Snakes and ladder problem, Given all the inputs for the board.
We can roll the dice, as we want to. Need to find the shortest path to reach the 100
level from the starting of the path. Various other questions were asked on the basis
of that only.
2. Given a file with millions of words, need to find top K words on the basis of
occurrence.
2nd Telephonic
1. Given a list a1,a2,a3.an. Comparison between elements is given like a1>a2,
a3>a5, a4>a2..etc. We need to find whether is there any situation that we can
sort the list in to the ascending order on the basis of comparison. Yes or No ,
explain the conditions
2. Given a string example : shoppingwithflipkartiseasy, Now we are given this string
and a dictionary containing valid words , now we need to break the sentence into
words separated by space. Output : shopping with flipkart is easy
Onsite
Coding Round
1. Need to write a fully functionally and working code for a problem statement.
Problem is to write the code for maintaining a directory for any organization where
employee will have id, name, post and manager as attribute. Basically two features
need to be implemented: (a). Should be able to do searching on the basis of name,
prefix search for the name should also be supported, (b). For any employee, we
can get the list of all the subordinates which comes under him/her, like for ceo , all
the employees list should get displayed
2. No database is needed, memory storage was asked to used for this
3. Code should be extendable so that new attributes for the employee can be
added
4. Approach for maintaining the structure and optimality in searching for required.
Face to Face
1. Given a file containing billions of words, need to find top K words. Other
variations like the file size is 100 MB and we can read only a chunk of data at a
time, how to maintain that, etc
2. Given a series 2,3,4,5,6,8,9,10,, here in this series all the numbers are
present which have factors only and only either 2,3 or 5. Need to write a node to
generate nth number for the series . With best approach and complexity
3. Given a Alien language, we have the dictionary of that language , but we have
only very few words, but they are all arranged in the lexicographical order. We need
to first find whether we will be able to get a alphabetical order or not, if yes explain
approach
for value of any tag given a value of tag at any sub levels.
First there was discussion as to how to go about the problem and the algorithm.
Then 1 hour for coding the solution. Finally the code was evaluated and some
extensions to the solutions were discussed
In-House Round 2: Hiring Manager (45 mins)
The Hiring Manager was on leave and hence had the interview via phone. This
round was a cultural fit round. The manager checks whether we will fit into the
companys work environment. Few questions like,
1) Some unix commands since they work extensively on UNIX platforms.
2) Achievements.
3) Details on previous projects.
4) Most challenging situation.
5) Estimations that need to be done for a project and considerations
Some more questions like these.
In-House Round 3: PS & DS Algo (1 hour)
1) Merge k sorted arrays.
2) Given a tree with edge weights, find any path in the tree with maximum sum of
edges.
3) Given a maze, a start point and end point find the shortest path to reach the end
point from the starting point.
4) Given a polygon and a point, find whether the point lies within the polygon or not.
After a week, the HR contacted me and I got through the interviews.
Excellent facilities and salary package for candidates who get selected.
Q2) Given N meeting with their start time s1, s2 .sn and end time e1, e2 .en
and K rooms. How to schedule maximum of N meetings in k rooms. (Concept:
Interval partitioning using greedy approach).
Called for onsite interview. All expenses flight, hotel, cab etc..were taken care by
company.
Round 4: 1st f2f interview (Machine Coding round) (1hour 10 min)
Given a string regex and another string pat find whether the pattern is acceptable
against given regex string.
Regex string contains following characters and special characters:
1. Normal alphabets a to z and A to Z
2. $ all string should end with all characters preceding $
Example:
Regex :abc$ ,
Pattern: abcd(Not acceptable) , abc(acceptable), ab(Not acceptable),
dhfusdhabc(acceptable) etc..
3. ^ all string should start with all characters exceeding ^
Example: Regex : ^abc
Pattern: abcd(acceptable) , abc(acceptable), ab(Not acceptable), dhfusdhabc(NOT
acceptable) etc..
Regex: ^ then only pattern acceptable is null.
4. . any character can be mapped to dot except null
Example 1: Regex : .abc
Pattern: Zabc(acceptable) , abc(NOT acceptable), ab(Not acceptable),
habc(acceptable) etc..
Example 2: Regex :a.bc
Pattern: abc(NOT acceptable) , aXbc(acceptable), ab(Not acceptable), habc(NOT
acceptable) etc..
5. *-the character just preceding * can be repeated n time where (n>=0)
Example 1: Regex :abc*de
Pattern: abccccccccccde (acceptable), abcde(acceptable), abcccd(not acceptable)
Code should follow OOPs principle such as modularity (make each function for
each special character), encapsulation etc.
Further discussion on improving the code and how would other person can see the
code and add other functions to it.
Round 5: 2nd f2f interview (Problem solving and data structure round) (1 1.5
hr)
Q1). Generate n numbers in ascending order which are having given k factors.
Discuss various approaches. Discussed on various approaches.
I told 3 approaches:
Nave approachO(nk)
Heap approach O(nlogk),
Linear time O(n)
Q2). Given set of words which I have to treat as dictionary as new lexicographic
order. I have to learn from set of string as print lexicographic order of each
character. (Topological sort) (http://www.geeksforgeeks.org/topological-sorting/)
1. Given an array of n distinct integers sorted in ascending order. Find an index i s.t
ar[i] = i. Return -1 if no such index exists. Note that integers in array can be
negative.
2. Design a stack which holds an integer value such that getMinimum() function
should return the minimum element in the stack.
FOLLOW UP: Implement popMin() function which would pop minimum element
from the original stack. O(1) implementation was required.(Hint: Use LinkedList to
implement stack and store address of minimum element node in min-stack)
3. Print an organisational hierarchy.
Naveen manages Satish
Satish manages Anushree
Satish manages Sandeep
Gurinder manages Naveen
Gurinder->Naveen
Naveen->Satish
Satish->Anushree,Sandeep
Anushree->
Sandeep->
Round-2: Telephonic (30 mins)
1. Given an array which is first strictly increasing and then strictly decreasing. Find
an element in this array.Discussions on various approaches and their complexities.
After these two rounds, I was called for Face-2-Face discussions in Bangalore.
There I had 4 rounds.
Round-3: In-House Coding(1 Hour 45 mins)
Write a running code in any language to implement the famous tic-tac-toe game.
First there was discussion on various approaches and basic functions which would
be required to implement the same. Then I was asked to code.
I was given 1 hour 15 mins to code this.I had to design this game as per following:
1) Game has 3 modes: Human Vs Human, Human Vs Computer and
Computer Vs Computer.
2) Initially start with 3X3 grid, but it can be generalised to NXN grid. So dont
hardcode any variable.
3) Minimise Code Redundancy and try to make it as modular as posible.
4) Try to use abstraction and expose lesser number of functions(APIs) to
outside world.
5) Try to cover maximum number of edge cases, like when to abort the game,
draw condition, win condition, overwriting existing value in grid etc)
After I wrote running code for the same, I was told to explain my code and then run
with some test cases. Then he asked me to mail the code.
I told him that we would first sort the interval on basis of starting numbers. Then
merge overlapping intervals to get a set of non-overlapping intervals like 5-10,
15-20, 25-45, 50-100. Now we can find the ith smallest number after finding the
appropriate interval.
FOLLOW UP: He then modified this question to accomodate duplicate numbers
also.
Suppose we have intervals like 5-10, 8-12.
Then total numbers in these two intervals would be:
{5,6,7,8,8,9,9,10,10,11,12}
So, 1st smallest number: 5
4th smallest number: 8
5th smallest number: 8 (here is the
change since now we have duplicate elements also) and so on.
3. Given a dictionary of 50,000 words. Given a phrase without spaces, add spaces
to make it a proper sentence.
e.g:input: thequickbrownfoxjumpoverlazydog
output: the quick brown fox jump over lazy dog
FOLLOW UP Questions:
common HR questions like why Flipkart, Why should we hire you etc.
\
5
1
5
/
1
2
=>
/ \
1 5
2
\
=>
5
Not superimposable
(3) Given a review paragraph and keywords, find minimum length snippet from
paragraph which contains all keywords in any order.
(4) Extended question 3 if there are millions of review, what preprocessing step
would you do.
Coding Round: (1 hour 30 minutes)
Given list of expressions:
a = 10
b = a++
c=a+b
d = c*b + a*c
Print out value of last variable (in our example, it is d). First illustrate algorithm and
then code in 1 hour.
Managerial Round: (1 hour)
Designing of all previous products I have worked on.
Design Round: (1 hour)
Design Snake and Ladder game.
Expose api to outer world.
Build following from exposed api:
(1) iOS app
(2) Web app
(3) Desktop app
HR Round: (15 minutes)
Why would you join Flipkart if you would have offer from Google and Facebook?
Why you want to join Flipkart?
After few days I received offer. Thank you Geeks as reading geeksforgeeks was
wonderful and great learning experience and helped in preparation for interview.