Skip to content

Commit 0adca92

Browse files
Merge pull request #15 from KatieONell/main
katie solution 2582
2 parents 97261e6 + bc7355e commit 0adca92

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

problems/2582/katie.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# [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+
class Solution:
24+
def passThePillow(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+
<img width="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

Comments
 (0)