Hi all: I've gotten this question like four times interviewing in silicon valley. What is the correct solution?
Shuffling a deck of cards. The problem description is as follows:
You are given a deck containing n cards. While holding the deck:
- Take the top card off the deck and set it on the table
- Take the next card off the top and put it on the bottom of the deck in your hand.
- Continue steps 1 and 2 until all cards are on the table. This is a round.
- Pick up the deck from the table and repeat steps 1-3 until the deck is in the original order.
Write a program to determine how many rounds it will take to put a deck back into the original order.
What is this particular question called? Does it have a name?