3178. Find the Child Who Has the Ball After K Seconds Easy
1/**
2 * [3178] Find the Child Who Has the Ball After K Seconds
3 *
4 * You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right.
5 * Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches either end of the line, i.e. child 0 or child n - 1, the direction of passing is reversed.
6 * Return the number of the child who receives the ball after k seconds.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">n = 3, k = 5</span>
11 * Output: <span class="example-io">1</span>
12 * Explanation:
13 * <table>
14 * <tbody>
15 * <tr>
16 * <th>Time elapsed</th>
17 * <th>Children</th>
18 * </tr>
19 * <tr>
20 * <td>0</td>
21 * <td>[<u>0</u>, 1, 2]</td>
22 * </tr>
23 * <tr>
24 * <td>1</td>
25 * <td>[0, <u>1</u>, 2]</td>
26 * </tr>
27 * <tr>
28 * <td>2</td>
29 * <td>[0, 1, <u>2</u>]</td>
30 * </tr>
31 * <tr>
32 * <td>3</td>
33 * <td>[0, <u>1</u>, 2]</td>
34 * </tr>
35 * <tr>
36 * <td>4</td>
37 * <td>[<u>0</u>, 1, 2]</td>
38 * </tr>
39 * <tr>
40 * <td>5</td>
41 * <td>[0, <u>1</u>, 2]</td>
42 * </tr>
43 * </tbody>
44 * </table>
45 * </div>
46 * <strong class="example">Example 2:
47 * <div class="example-block">
48 * Input: <span class="example-io">n = 5, k = 6</span>
49 * Output: <span class="example-io">2</span>
50 * Explanation:
51 * <table>
52 * <tbody>
53 * <tr>
54 * <th>Time elapsed</th>
55 * <th>Children</th>
56 * </tr>
57 * <tr>
58 * <td>0</td>
59 * <td>[<u>0</u>, 1, 2, 3, 4]</td>
60 * </tr>
61 * <tr>
62 * <td>1</td>
63 * <td>[0, <u>1</u>, 2, 3, 4]</td>
64 * </tr>
65 * <tr>
66 * <td>2</td>
67 * <td>[0, 1, <u>2</u>, 3, 4]</td>
68 * </tr>
69 * <tr>
70 * <td>3</td>
71 * <td>[0, 1, 2, <u>3</u>, 4]</td>
72 * </tr>
73 * <tr>
74 * <td>4</td>
75 * <td>[0, 1, 2, 3, <u>4</u>]</td>
76 * </tr>
77 * <tr>
78 * <td>5</td>
79 * <td>[0, 1, 2, <u>3</u>, 4]</td>
80 * </tr>
81 * <tr>
82 * <td>6</td>
83 * <td>[0, 1, <u>2</u>, 3, 4]</td>
84 * </tr>
85 * </tbody>
86 * </table>
87 * </div>
88 * <strong class="example">Example 3:
89 * <div class="example-block">
90 * Input: <span class="example-io">n = 4, k = 2</span>
91 * Output: <span class="example-io">2</span>
92 * Explanation:
93 * <table>
94 * <tbody>
95 * <tr>
96 * <th>Time elapsed</th>
97 * <th>Children</th>
98 * </tr>
99 * <tr>
100 * <td>0</td>
101 * <td>[<u>0</u>, 1, 2, 3]</td>
102 * </tr>
103 * <tr>
104 * <td>1</td>
105 * <td>[0, <u>1</u>, 2, 3]</td>
106 * </tr>
107 * <tr>
108 * <td>2</td>
109 * <td>[0, 1, <u>2</u>, 3]</td>
110 * </tr>
111 * </tbody>
112 * </table>
113 * </div>
114 *
115 * Constraints:
116 *
117 * 2 <= n <= 50
118 * 1 <= k <= 50
119 *
120 *
121 * Note: This question is the same as <a href="https://leetcode.com/problems/pass-the-pillow/description/" target="_blank"> 2582: Pass the Pillow.</a>
122 *
123 */
124pub struct Solution {}
125
126// problem: https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/
127// discuss: https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/discuss/?currentPage=1&orderBy=most_votes&query=
128
129// submission codes start here
130
131impl Solution {
132 pub fn number_of_child(n: i32, k: i32) -> i32 {
133 0
134 }
135}
136
137// submission codes end
138
139#[cfg(test)]
140mod tests {
141 use super::*;
142
143 #[test]
144 fn test_3178() {
145 }
146}
147
Back
© 2025 bowen.ge All Rights Reserved.