## 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``

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

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

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

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.

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.

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

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

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

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

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.

### 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.