Find the Child Who Has the Ball After K Seconds

EasyMathSimulation

Solution

export function numberOfChild(n: number, k: number): number {
  const rounds = 2 * (n - 1);
  const remain = k % rounds;
  return remain < n ? remain : rounds - remain;
}