You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# [Problem 2582: Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/description/)
2
+
3
+
## Initial thoughts (stream-of-consciousness)
4
+
I took a couple examples and wrote them down in a grid like so:
5
+
6
+
| 1 | 2 | 3 | 4 |
7
+
|---|---|---|---|
8
+
| x | 1 | 2 | 3 |
9
+
| 6 | 5 | 4 | x |
10
+
| x | 7 | 8 | 9 |
11
+
| . | . | . | . |
12
+
13
+
Which made me realize it was a parity problem. If you take `n-1` as your divisor, the quotient will tell you what row it ends up on and the remainder will tell you how many indeces in from the edge you have to go (the direction changes based on the parity of the quotient).
14
+
15
+
## Refining the problem
16
+
* first, divide `time` by `n-1` and get the remainder
17
+
* then check the parity of the quotient:
18
+
* if even, return `r+1`
19
+
* if odd, return `n-r`
20
+
21
+
## Attempted solution(s)
22
+
```python
23
+
classSolution:
24
+
defpassThePillow(self, n: int, time: int) -> int:
25
+
r = time%(n-1)
26
+
if (time//(n-1))%2==0:
27
+
return (r+1)
28
+
else:
29
+
return (n-r)
30
+
```
31
+
<imgwidth="714"alt="Screen Shot 2024-07-05 at 9 31 05 PM"src="https://github.com/KatieONell/leetcode-solutions/assets/12962290/1e1c5756-94ed-4a40-b12b-724d6e914755">
0 commit comments