2811. Check if it is Possible to Split Array Medium

@problem@discussion
#Array#Dynamic Programming#Greedy



1/**
2 * [2811] Check if it is Possible to Split Array
3 *
4 * You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n arrays of size 1 by performing a series of steps.
5 * An array is called good if:
6 * 
7 * 	The length of the array is one, or
8 * 	The sum of the elements of the array is greater than or equal to m.
9 * 
10 * In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two arrays, if both resulting arrays are good.
11 * Return true if you can split the given array into n arrays, otherwise return false.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [2, 2, 1], m = 4</span>
16 * Output: <span class="example-io">true</span>
17 * Explanation:
18 * 
19 * 	Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.
20 * 	Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [2, 1, 3], m = 5</span>
25 * Output: <span class="example-io">false</span>
26 * Explanation:
27 * The first move has to be either of the following:
28 * 
29 * 	Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.
30 * 	Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.
31 * 
32 * So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split nums into n arrays of size 1.
33 * </div>
34 * <strong class="example">Example 3:
35 * <div class="example-block">
36 * Input: <span class="example-io">nums = [2, 3, 3, 2, 3], m = 6</span>
37 * Output: <span class="example-io">true</span>
38 * Explanation:
39 * 
40 * 	<span class="example-io">Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].</span>
41 * 	<span class="example-io">Split [3, 3, 2, 3] to [3, 3, 2] and [3].</span>
42 * 	<span class="example-io">Split [3, 3, 2] to [3, 3] and [2].</span>
43 * 	<span class="example-io">Split [3, 3] to [3] and [3].</span>
44 * </div>
45 *  
46 * Constraints:
47 * 
48 * 	1 <= n == nums.length <= 100
49 * 	1 <= nums[i] <= 100
50 * 	1 <= m <= 200
51 * 
52 */
53pub struct Solution {}
54
55// problem: https://leetcode.com/problems/check-if-it-is-possible-to-split-array/
56// discuss: https://leetcode.com/problems/check-if-it-is-possible-to-split-array/discuss/?currentPage=1&orderBy=most_votes&query=
57
58// submission codes start here
59
60impl Solution {
61    pub fn can_split_array(nums: Vec<i32>, m: i32) -> bool {
62        false
63    }
64}
65
66// submission codes end
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71
72    #[test]
73    fn test_2811() {
74    }
75}
76


Back
© 2025 bowen.ge All Rights Reserved.