Flipkart Interview Experience | Set 40 (For SDE 1)
I was interviewed for Software Development Engineering (SDE1) role Flipkart.
Round 1: Machine Coding round: (90 minutes)
Given a binary tree as a sequence of (parent, child) tuples: (A B)(A C)(B G)(C H)(E F)(B D)(C E) Write a program to find following errors in the tree:
- E1: More than 2 children
- E2: Duplicate Tuples
- E3: Cycle present
- E4: Multiple roots
- E5: Multiple parents
Input is a expression containing parent child relations. output is Error codes or success.
Sample test cases
- Input: (A B)(A C)(B G)(C H)(E F)(B D)(C E) Output: Success
- Input: (A B)(A C)(A D) Output: E1
- Input: (A B)(A B) Output: E2
- Input: (A B)(B C)(C A) Output: E3
- Input: (A B)(C D) Output: E4
- Input: (A B)(B C)(A C) Output: E5
Solution
Code is written in node.js javascript. Tests are using mocha. Major trick in this question is that the data structure need to hold such data is not a binary tree but a graph. Or a graph with two sets of edges children and parents.
I used this DS in javascript to solve:
function Node(data) {
this.data = data;
this.children = [];
this.parents = [];
}
Cycle detection can be done using http://www. geeksforgeeks.org/detect- cycle-in-a-graph/
My solution: https://github.com/niklabh/ tree-error-checker
Round 2: Face to Face
1. Design a load balancer which implements following methods:
- add(n) where n is id of instance
- remove(n) where n is id of instance
- getRandom() which returns a random instance.
All these operation should be of order O(1).
Followup for this question was to change getRandom in such a way that it returns with weighted randomness rather than uniform randomness if weights is associated with instances.
2. You are given a result of cricket tournament with all the wins and losses. Print the teams in such a way that a winning team is always at the right of losing team.
Solution: Store the results as a Directed Acyclic Graph and run topological sort algo.
Round 3: Face to Face
- Explain your projects in detail
- Key metrics about your project i.e. how much load it handled etc.
- If you are storing same data in separate DBs how will you keeping them in sync.
- If you are to write your project from scratch what will you change?
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Recommended Posts:
- Flipkart Interview Experience | Set 15B
- Flipkart Interview Experience | Set 41 (For SDE 1)
- Flipkart Interview Experience | Set 26
- Flipkart Interview Experience | Set 24
- Flipkart Interview Experience| Set 38 (For SDE II)
- Flipkart Interview Experience | Set 20 (For SDE-II)
- Flipkart Interview Experience | Set 47
- Flipkart Interview Experience | Set 49
- Flipkart Interview Experience | Set 17 (For SDE II)
- Flipkart Interview Experience | Set 32 (For SDE-1)
- Flipkart Interview Experience for SDE 2
- Flipkart Interview Experience | Set 21
- Flipkart Interview Experience | Set 23
- Flipkart Interview Experience SDE 2
- Flipkart Interview Experience | Set 27 (For SDE)



