Find the Winner of the Circular Game

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
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. More formally, moving clockwise from the i<sup>th</sup> friend brings you to the (i+1)<sup>th</sup> friend for 1 <= i < n, and moving clockwise from the n<sup>th</sup> friend brings you to the 1<sup>st</sup> friend.
The rules of the game are as follows:
Start at the
1<sup>st</sup>friend.Count the next
kfriends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.The last friend you counted leaves the circle and loses the game.
If there is still more than one friend in the circle, go back to step
2starting from the friend immediately clockwise of the friend who just lost and repeat.Else, the last friend in the circle wins the game.
Given the number of friends, n, and an integer k, return the winner of the game.
LeetCode Problem - 1823
import java.util.Queue;
import java.util.LinkedList;
class Solution {
// Method to find the winner of the game
public int findTheWinner(int n, int k) {
Queue<Integer> queue = new LinkedList<>();
// Add all participants to the queue
for (int i = 1; i <= n; i++) {
queue.add(i);
}
// Process the queue until only one participant remains
while (queue.size() > 1) {
// Move the first k-1 participants to the back of the queue
for (int i = 0; i < k - 1; i++) {
queue.add(queue.poll());
}
// Remove the k-th participant from the queue
queue.poll();
}
// The remaining participant is the winner
return queue.peek();
}
}




