2582. Pass the Pillow Easy

@problem@discussion
#Math#Simulation



1/**
2 * [2582] Pass the Pillow
3 *
4 * There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.
5 * 
6 * 	For example, once the pillow reaches the n^th person they pass it to the n - 1^th person, then to the n - 2^th person and so on.
7 * 
8 * Given the two positive integers n and time, return the index of the person holding the pillow after time seconds.
9 *  
10 * <strong class="example">Example 1:
11 * 
12 * Input: n = 4, time = 5
13 * Output: 2
14 * Explanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.
15 * After five seconds, the 2^nd person is holding the pillow.
16 * 
17 * <strong class="example">Example 2:
18 * 
19 * Input: n = 3, time = 2
20 * Output: 3
21 * Explanation: People pass the pillow in the following way: 1 -> 2 -> 3.
22 * After two seconds, the 3^r^d person is holding the pillow.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	2 <= n <= 1000
28 * 	1 <= time <= 1000
29 * 
30 *  
31 * Note: This question is the same as <a href="https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/description/" target="_blank"> 3178: Find the Child Who Has the Ball After K Seconds.</a>
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/pass-the-pillow/
37// discuss: https://leetcode.com/problems/pass-the-pillow/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn pass_the_pillow(n: i32, time: i32) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2582() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.