Find the Child Who Has the Ball After K Seconds

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.
You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right.
Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches either end of the line, i.e. child 0 or child n - 1, the direction of passing is reversed.
Return the number of the child who receives the ball after k seconds.
LeetCode Problem - 3178
class Solution {
public int numberOfChild(int n, int k) {
// Decrease n by 1 to adjust for the problem's specific requirements
n--;
// Calculate the number of complete rounds
int rounds = k / n;
// Calculate the remainder, which is the position in the current round
int rem = k % n;
// If the number of complete rounds is even, return the remainder
if(rounds % 2 == 0) {
return rem;
} else {
// If the number of complete rounds is odd, return the adjusted position
return n - rem;
}
}
}




