Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-05-11_12-04-32.png
45.8 KB
#medium
#N1823. Find the Winner of the Circular Game
problem link
#solution
class Solution {
public int findTheWinner(int n, int k) {
int cycle=n-1, curr=0, temp;
int[] arr = new int[n];
while(cycle-- >0){
temp=0;
while(temp<k){
if(arr[curr%n]==0) temp++;
if(temp<k) curr++;
}
arr[curr%n]++;
curr++;
}

for(int i=0; i<arr.length; i++){
if(arr[i]==0) return i+1;
}
return -1;
}
}