Flipkart Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
3
of 3 vote

Perform Inorder traversal of binary tree and then Inversion Count on the formed array.
The inversion count will be the minimum number of swaps required to bring the array in ascending order which is inorder of BST.

- csemanoj May 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Assuming, swapping is restricted to adjacent node only.

- csemanoj May 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@csemanoj: That wouldn't be the condition that would make this solution right. Adjacent nodes in a BST are not always in-order successors, and not all in-order successors are adjacent. To make inversion counting correct, you'd have to have a condition that says you can only swap in-order successors, but that seems very contrived.

- eugene.yarovoi May 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Inorder traversal and Inversion count is the right
answer !!

But assuming to swap only adjacent nodes may not be a good.

Simply improvise the inversion count algorithm to do a divide and conquer approach with a midpoint for the inorder array and figure out all the swaps required not just adjacent.

- P.D May 19, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More