Tap here to switch tabs
Problem
Submissions

Problem: Pass the Pillow

med
30 min
Try to solve the Pass the Pillow problem.

Statement

There are n people standing in a line, labeled sequentially from 11 to n. Initially, person 11 holds a pillow.

Every second, the person holding the pillow passes it to the next adjacent person. When the pillow reaches either end of the line, the direction reverses, and people continue passing it in the opposite direction.

Given two positive integers n and time, return the label of the person holding the pillow after time seconds.

Constraints:

  • 2≤2 \leq n ≤1000\leq 1000

  • 1≤1 \leq time ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Pass the Pillow

med
30 min
Try to solve the Pass the Pillow problem.

Statement

There are n people standing in a line, labeled sequentially from 11 to n. Initially, person 11 holds a pillow.

Every second, the person holding the pillow passes it to the next adjacent person. When the pillow reaches either end of the line, the direction reverses, and people continue passing it in the opposite direction.

Given two positive integers n and time, return the label of the person holding the pillow after time seconds.

Constraints:

  • 2≤2 \leq n ≤1000\leq 1000

  • 1≤1 \leq time ≤1000\leq 1000