You're given an integer array where one element dominates more than half the positions. Your task is to find the minimum index where you can split this array into two parts, such that both parts have the same dominant element.
A dominant element is one that appears in more than half the positions of an array. For example, in [3, 3, 3, 2, 2], the number 3 is dominant because it appears 3 times out of 5 positions (more than 2.5).
Goal: Find the smallest index i where splitting at position i creates two subarrays that both have the same dominant element as the original array.
Input: An integer array nums with exactly one dominant element
Output: The minimum valid split index, or -1 if no valid split exists
Example: nums = [1,1,1,2,2,2,2] โ The dominant element is 2. We need to find where to split so both parts are dominated by 2.
Input & Output
Constraints
- 3 โค nums.length โค 105
- 1 โค nums[i] โค 109
- nums contains exactly one dominant element