Skip to content

Commit 180d455

Browse files
Updated
1 parent 52f9ca9 commit 180d455

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

dsa-solutions/lc-solutions/1800-1899/1823-find-the-winner-of-the-circular-game.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
id: find-the-winner-of-the-circular-game
33
title: Find the Winner of the Circular Game
44
sidebar_label: 1823 - Find the Winner of the Circular Game
5-
tags: [Array]
5+
tags:
6+
- Array
7+
68
description: "This is a solution to the Find the Winner of the Circular Game problem on LeetCode."
79
---
810

@@ -11,7 +13,7 @@ There are n friends that are playing a game. The friends are sitting in a circle
1113

1214
### Examples
1315

14-
*Example 1:*
16+
**Example 1:**
1517

1618
```
1719
Input: n = 5, k = 2
@@ -28,7 +30,7 @@ Explanation: Here are the steps of the game:
2830
9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
2931
```
3032

31-
*Example 2:*
33+
**Example 2:**
3234
```
3335
Input: n = 6, k = 5
3436
Output: 1
@@ -45,11 +47,11 @@ Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is frien
4547
1. **Initialization**:
4648
- Initialize a variable `winner` to keep track of the winner found.
4749

48-
2. *Iterate Through the Numbers*:
50+
2. **Iterate Through the Numbers**:
4951
- Use a loop to iterate through each element.
5052
- Apply the formula `(winner + k - 1) % (i + 1) + 1` to find the new winner.
5153

52-
3. *Return the Result*:
54+
3. **Return the Result**:
5355
- After iterating through all elements, return the value of `winner` as the result.
5456

5557
<Tabs>
@@ -83,13 +85,12 @@ function Solution() {
8385
</div>
8486
);
8587
}
86-
87-
```
88+
```
8889
8990
#### Complexity Analysis
9091
91-
- **Time Complexity:** $ O(n) $ because of iterating through the elements
92-
- **Space Complexity:** $ O(1) $
92+
- Time Complexity: $ O(n) $ because of iterating through the elements
93+
- Space Complexity: $ O(1) $
9394
9495
## Code in Different Languages
9596
<Tabs>
@@ -147,7 +148,6 @@ public class Solution {
147148
}
148149
```
149150
</TabItem>
150-
151151
<TabItem value="C++" label="C++">
152152
<SolutionAuthor name="@Ishitamukherjee2004"/>
153153
```cpp
@@ -165,10 +165,13 @@ public:
165165
</TabItem>
166166
</Tabs>
167167
168+
</TabItem>
169+
</Tabs>
168170
169171
170172
171173
## References
172174
173-
- *LeetCode Problem*: [Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
174-
- *Solution Link*: [LeetCode Solution](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
175+
- **LeetCode Problem**: [Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
176+
177+
- **Solution Link**: [LeetCode Solution](https://leetcode.com/problems/find-the-winner-of-the-circular-game)

0 commit comments

Comments
 (0)