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?
- A. 2
- B. 1
- C. 0
- 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
- Problem: Lamps 1 to 20 are all off. For each pass i = 1 to 20, every lamp whose number is a multiple of i is toggled. How many lamps are…
- Problem: Count integers from 1 to 100 that are divisible by 3 or by 5 but not by 15.
- Problem: Compute 2^(2^5) mod 1000 (that is, 2 raised to the power 32, taken modulo 1000).
- Problem: With coin denominations 1, 7 and 10, what is the minimum number of coins needed to make 97?
- Problem: Job sequencing: five jobs (deadline, profit) are (2, 100), (1, 19), (2, 27), (1, 25), (3, 15). Each job takes one unit of time…
- Problem: Boats carry at most 2 people and a weight limit of 10 per boat. Four people weigh 3, 5, 3 and 4. What is the minimum number of…