cards wraps around, so the first card follows the last one. With n = len(cards), the neighbours of card i are (i + 1) % n and (i - 1 + n) % n.
You stand at the card with index start, and each step takes you to a neighbouring card, in either direction.
Return the fewest steps needed to reach a card showing the word wanted. If no card shows that word, return -1.cards=['sun', 'moon', 'star', 'comet', 'moon', 'sky'], wanted='sky', start=1 → 2
From position 1, "sky" (position 5) is 4 steps forward, but only 2 steps backward around the ring: 1 → 0 → 5.
cards=['red', 'blue', 'red'], wanted='red', start=2 → 0
The wanted word is right at the starting position, so no moves are needed.
cards=['one', 'two'], wanted='three', start=0 → -1
"three" is not on the ring at all, so the answer is -1.
len(cards) ≤ 100cards and of wanted ≤ 100start < len(cards)cards=['sun', 'moon', 'star', 'comet', 'moon', 'sky'], wanted='sky', start=1
2
Run checks the first 3 tests in your browser. Submit checks all 245 tests on the server, hidden ones included.