2780. Minimum Index of a Valid Split
- Because we split array into 2 sub array, the findCount must >= 2/n (arr element count)
- Just compare current left subarray, and right subarray if they meet requirement.
class Solution:
def minimumIndex(self, nums: List[int]) -> int:
n = len(nums)
findCount = ceil(float(n) / 2)
c = Counter(nums)
for key, value in list(c.items()):
if value < findCount:
c.pop(key)
M = defaultdict(int)
for i in range(n):
if nums[i] not in c:
continue
M[nums[i]] += 1
c[nums[i]] -= 1
if 2 * M[nums[i]] > i + 1 and 2 * c[nums[i]] > n - i - 1:
return i
return -1