2740. Find the Value of the Partition Medium
1/**
2 * [2740] Find the Value of the Partition
3 *
4 * You are given a positive integer array nums.
5 * Partition nums into two arrays, nums1 and nums2, such that:
6 *
7 * Each element of the array nums belongs to either the array nums1 or the array nums2.
8 * Both arrays are non-empty.
9 * The value of the partition is minimized.
10 *
11 * The value of the partition is |max(nums1) - min(nums2)|.
12 * Here, max(nums1) denotes the maximum element of the array nums1, and min(nums2) denotes the minimum element of the array nums2.
13 * Return the integer denoting the value of such partition.
14 *
15 * <strong class="example">Example 1:
16 *
17 * Input: nums = [1,3,2,4]
18 * Output: 1
19 * Explanation: We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].
20 * - The maximum element of the array nums1 is equal to 2.
21 * - The minimum element of the array nums2 is equal to 3.
22 * The value of the partition is |2 - 3| = 1.
23 * It can be proven that 1 is the minimum value out of all partitions.
24 *
25 * <strong class="example">Example 2:
26 *
27 * Input: nums = [100,1,10]
28 * Output: 9
29 * Explanation: We can partition the array nums into nums1 = [10] and nums2 = [100,1].
30 * - The maximum element of the array nums1 is equal to 10.
31 * - The minimum element of the array nums2 is equal to 1.
32 * The value of the partition is |10 - 1| = 9.
33 * It can be proven that 9 is the minimum value out of all partitions.
34 *
35 *
36 * Constraints:
37 *
38 * 2 <= nums.length <= 10^5
39 * 1 <= nums[i] <= 10^9
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/find-the-value-of-the-partition/
45// discuss: https://leetcode.com/problems/find-the-value-of-the-partition/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn find_value_of_partition(nums: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_2740() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.