← back to unit
Medium
# queues medium
Hot Potato
The circle passes the potato; every k-th holder is OUT, and the circle closes up. Last kid standing wins. 🥔
You get the names (passing starts at the first name) and the count k. Each round, the potato makes k-1 passes and the holder is eliminated. Print the winner.
Example:
Input: names = ["mia", "leo", "kai", "ana", "bo"], k = 3
Output: ana
Passing the potato 2 times (k - 1) before each elimination works through the circle, round after round, until only ana remains.
💡 need a hint?
q-hot-potato.py🔒 given lines are locked — write your code in between
loading...