
Given an integer array nums of even length n, calculate the difference between the maximum value in the first half of the array and the minimum value in the second half of the array. Specifically, find the maximum value in the subarray nums[0 ... n/2 - 1] and the minimum value in the subarray nums[n/2 ... n - 1], and return the result of subtracting the minimum of the second half from the maximum of the first half.
Follow-up: How would you modify your solution if the array length could be odd, with the middle element included in both halves?
Explanation: The first half is [3, 8, 2] with a maximum of 8. The second half is [5, 1, 6] with a minimum of 1. The difference is 8 - 1 = 7.
Explanation: The maximum of the first half [-10, -5] is -5. The minimum of the second half [-20, -1] is -20. The difference is -5 - (-20) = 15.
Access the full code editor, ThinkBuddy AI hints, and track your progress.