Leetcode Practice
LC 2582. Pass the Pillow
- Last updated
- Reading time
- 1 min read
The problem
Solution
function passThePillow(n: number, time: number): number {
let direction = 1
let idx = 1
while (time) {
idx += direction
if (idx === 1 || idx === n) {
direction *= -1
}
time--
}
return idx
}