2780. Minimum Index of a Valid Split
An element
x
of an integer arrayarr
of lengthm
is dominant iffreq(x) * 2 > m
, wherefreq(x)
is the number of occurrences ofx
inarr
. Note that this definition implies thatarr
can have at most one dominant element.You are given a 0-indexed integer array
nums
of lengthn
with one dominant element.You can split
nums
at an indexi
into two arraysnums[0, ..., i]
andnums[i + 1, ..., n - 1]
, but the split is only valid if:
0 <= i < n - 1
nums[0, ..., i]
, andnums[i + 1, ..., n - 1]
have the same dominant element.Here,
nums[i, ..., j]
denotes the subarray ofnums
starting at indexi
and ending at indexj
, both ends being inclusive. Particularly, ifj < i
thennums[i, ..., j]
denotes an empty subarray.Return the minimum index of a valid split. If no valid split exists, return
-1
.
1 | class Solution { |