Skip to content

Commit 11ff6c7

Browse files
authored
katie solution 2582
1 parent dbbb608 commit 11ff6c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

problems/2582/katie.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
__ 01 02 03 04 05
7+
10 09 08 07 06 __
8+
__ 11 12 13 14 15
9+
10+
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).
11+
12+
## Refining the problem
13+
* first, divide `time` by `n-1` and get the remainder
14+
* then check the parity of the quotient:
15+
* if even, return `r+1`
16+
* if odd, return `n-r`
17+
18+
## Attempted solution(s)
19+
```python
20+
class Solution:
21+
def passThePillow(self, n: int, time: int) -> int:
22+
r = time%(n-1)
23+
if (time//(n-1))%2 == 0:
24+
return (r+1)
25+
else:
26+
return (n-r)
27+
```

0 commit comments

Comments
 (0)