-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path137.py
More file actions
25 lines (21 loc) · 694 Bytes
/
137.py
File metadata and controls
25 lines (21 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution:
def minimumIndex(self, nums: List[int]) -> int:
first_map = defaultdict(int)
second_map = defaultdict(int)
n = len(nums)
# Add all elements of nums to second_map
for num in nums:
second_map[num] += 1
for index in range(n):
# Create split at current index
num = nums[index]
second_map[num] -= 1
first_map[num] += 1
# Check if valid split
if (
first_map[num] * 2 > index + 1
and second_map[num] * 2 > n - index - 1
):
return index
# No valid split exists
return -1