Data Structures & AlgorithmsHardTCS NQT · Infosys

Problem: Eight cards labelled 1 to 8 are in a row. A perfect out-shuffle splits the deck into two equal halves (1–4 and 5–8) and interleaves them starting with the top card of the first half, so the order becomes 1, 5, 2, 6, 3, 7, 4, 8. Apply this shuffle 3 times. What is the position (1-indexed) of card 1 after the three shuffles?

  1. A. 2
  2. B. 1
  3. C. 0
  4. D. 3

Correct answer: B. 1

Each perfect shuffle interleaves the two halves with the first half's top card first. Following the whole deck through three shuffles shows it returns to the original order, so card 1 is back at the top; reading the second half first gives a different position.

More Coding Interview Problems questions

Exams that ask this topic