Pass the Pillow

EasyMathSimulation

Solution

export function passThePillow(n: number, time: number): number {
  const remain = time % (2 * (n - 1));
  return n - Math.abs(n - 1 - remain);
}