Flipkart Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

Just a correction:

2^(n/2)*3-1

- MichaelB April 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursive relation is:

T(n)  = 2 T((n-1)/2) + 1

Total operations required will be : 2^((n-1)/2) -1

- satyans24 August 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

T(n) = 2.T(n-2) + 3

- Anonymous October 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

T(n,r) = 2t(k,r)+t(n-k,r-1)
Where n is number of disks and r is number of pegs.

- Kiran April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

I don't know if it's optimal, but I managed to improve the minimum steps needed for a 3 peg problem, in a 4 peg problem.
let T(n) be the amount of steps needed to move "n" discsto another peg

T(n) = 2*T(n-2)+3

explanation: you move all but 2 discs to a helper,
then move the n-1 disc to helper2,
move the last disc to the destination,
then from helper2 to destination,
and lastly the n-2 discs to detination.

ultimately if sums up to

2^(n/2)-1

I used the 3 and 4 discs as a test and it seems to work.

- MichaelB April 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

could you please prove why choosing only 2 discs would minimize T(n) ?

- poorna.chandra.akp April 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Frame–Stewart algorithm, the number of discs to move needs to be calculated for the optimal solution.

- MichaelB April 29, 2014 | Flag


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