---
# System prepended metadata

title: 2780. Minimum Index of a Valid Split
tags: [Leetcode, HashMap, Medium, Math]

---

Link: https://leetcode.com/problems/minimum-index-of-a-valid-split/description/
## 思路
split完之后的两个array的dominant一定还是原array的dominant
不然不能保证两个array的dominant一样
因此我们先找到原array的dominant
然后遍历nums 直到找到一个可以把array分成两个dominant elements都等于原array的dominant的index就是答案
## Code
```python=
class Solution:
    def minimumIndex(self, nums: List[int]) -> int:
        counter = Counter(nums)
        for num, freq in counter.items():
            if freq*2 > len(nums):
                dominant = num
        
        dominantCount = 0
        for i, num in enumerate(nums):
            if num==dominant: dominantCount += 1
            if dominantCount*2>i+1 and (counter[dominant]-dominantCount)*2>len(nums)-i-1:
                return i
        return -1
```