Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #1823: Find the Winner of the Circular Game

In this guide, we solve Leetcode #1823 Find the Winner of the Circular Game in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order.

Quick Facts

  • Difficulty: Medium
  • Premium: No
  • Tags: Recursion, Queue, Array, Math, Simulation

Intuition

We need level-order exploration or shortest-step expansion, which maps directly to a queue.

BFS guarantees the first time you reach a node is the shortest in unweighted graphs.

Approach

Initialize the queue with starting nodes and expand outward layer by layer.

Track visited nodes to avoid cycles and redundant work.

Steps:

  • Initialize a queue with start nodes.
  • Pop, process, and enqueue neighbors.
  • Track visited nodes.

Example

Input: n = 5, k = 2 Output: 3 Explanation: Here are the steps of the game: 1) Start at friend 1. 2) Count 2 friends clockwise, which are friends 1 and 2. 3) Friend 2 leaves the circle. Next start is friend 3. 4) Count 2 friends clockwise, which are friends 3 and 4. 5) Friend 4 leaves the circle. Next start is friend 5. 6) Count 2 friends clockwise, which are friends 5 and 1. 7) Friend 1 leaves the circle. Next start is friend 3. 8) Count 2 friends clockwise, which are friends 3 and 5. 9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.

Python Solution

class Solution: def findTheWinner(self, n: int, k: int) -> int: if n == 1: return 1 ans = (k + self.findTheWinner(n - 1, k)) % n return n if ans == 0 else ans

Complexity

The time complexity is O(V+E). The space complexity is O(V).

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy