← Back to Data Structures & Algorithms
Question 558
Hot Potato
Hot Potato
Write hot_potato(names: list[str], k: int) -> str using from collections import deque: the names form a circle with the first name at the front. While more than one person remains, pass the potato k times, where one pass moves the person at the front to the back (append() what popleft() returns), and then remove the person now at the front, who is out. Return the last name left. With Bill David Susan Jane Kent Brad and a k of 7 the survivor is Susan. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, space-separated names (at least one) and then k; the tests print the name your function returns.
Expected Output:
Susan= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.