390. Elimination Game Medium
1/**
2 * [390] Elimination Game
3 *
4 * You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:
5 *
6 * Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.
7 * Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.
8 * Keep repeating the steps again, alternating left to right and right to left, until a single number remains.
9 *
10 * Given the integer n, return the last number that remains in arr.
11 *
12 * Example 1:
13 *
14 * Input: n = 9
15 * Output: 6
16 * Explanation:
17 * arr = [<u>1</u>, 2, <u>3</u>, 4, <u>5</u>, 6, <u>7</u>, 8, <u>9</u>]
18 * arr = [2, <u>4</u>, 6, <u>8</u>]
19 * arr = [<u>2</u>, 6]
20 * arr = [6]
21 *
22 * Example 2:
23 *
24 * Input: n = 1
25 * Output: 1
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= n <= 10^9
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/elimination-game/
36// discuss: https://leetcode.com/problems/elimination-game/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn last_remaining(n: i32) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_390() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.