2780. Minimum Index of a Valid Split
An element
xof an integer arrayarrof lengthmis dominant iffreq(x) * 2 > m, wherefreq(x)is the number of occurrences ofxinarr. Note that this definition implies thatarrcan have at most one dominant element.You are given a 0-indexed integer array
numsof lengthnwith one dominant element.You can split
numsat an indexiinto two arraysnums[0, ..., i]andnums[i + 1, ..., n - 1], but the split is only valid if:
0 <= i < n - 1nums[0, ..., i], andnums[i + 1, ..., n - 1]have the same dominant element.Here,
nums[i, ..., j]denotes the subarray ofnumsstarting at indexiand ending at indexj, both ends being inclusive. Particularly, ifj < ithennums[i, ..., j]denotes an empty subarray.Return the minimum index of a valid split. If no valid split exists, return
-1.
1 | class Solution { |