3828. Final Element After Subarray Deletions Medium

@problem@discussion
#Array#Math#Brainteaser#Game Theory



1/**
2 * [3828] Final Element After Subarray Deletions
3 *
4 * You are given an integer array nums.
5 * Two players, Alice and Bob, play a game in turns, with Alice playing first.
6 * 
7 * 	In each turn, the current player chooses any <span data-keyword="subarray-nonempty">subarray</span> nums[l..r] such that r - l + 1 < m, where m is the current length of the array.
8 * 	The selected subarray is removed, and the remaining elements are concatenated to form the new array.
9 * 	The game continues until only one element remains.
10 * 
11 * Alice aims to maximize the final element, while Bob aims to minimize it. Assuming both play optimally, return the value of the final remaining element.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,5,2]</span>
16 * Output: <span class="example-io">2</span>
17 * Explanation:
18 * One valid optimal strategy:
19 * 
20 * 	Alice removes [1], array becomes [5, 2].
21 * 	Bob removes [5], array becomes [2]​​​​​​​. Thus, the answer is 2.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [3,7]</span>
26 * Output: <span class="example-io">7</span>
27 * Explanation:
28 * Alice removes [3], leaving the array [7]. Since Bob cannot play a turn now, the answer is 7.
29 * </div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= nums.length <= 10^5
34 * 	1 <= nums[i] <= 10^5
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/final-element-after-subarray-deletions/
40// discuss: https://leetcode.com/problems/final-element-after-subarray-deletions/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn final_element(nums: Vec<i32>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_3828() {
58    }
59}
60

Back
© 2026 bowen.ge All Rights Reserved.