Skip to content

Commit e61d86c

Browse files
committed
Mar 27
1 parent fd9919b commit e61d86c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from collections import defaultdict
2+
3+
4+
class Solution:
5+
def minimumIndex(self, nums: list[int]) -> int:
6+
n = len(nums)
7+
map1, map2 = defaultdict(int), defaultdict(int)
8+
for num in nums:
9+
map2[num] += 1
10+
11+
for idx, num in enumerate(nums):
12+
map1[num] += 1
13+
map2[num] -= 1
14+
if map1[num] * 2 > idx + 1 and map2[num] * 2 > n - idx - 1:
15+
return idx
16+
return -1
17+
18+
19+
def main():
20+
nums = [1, 2, 2, 2]
21+
assert Solution().minimumIndex(nums) == 2
22+
23+
nums = [2, 1, 3, 1, 1, 1, 7, 1, 2, 1]
24+
assert Solution().minimumIndex(nums) == 4
25+
26+
nums = [3, 3, 3, 3, 7, 2, 2]
27+
assert Solution().minimumIndex(nums) == -1
28+
29+
30+
if __name__ == '__main__':
31+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
| March 24 | [3169. Count Days Without Meetings](https://leetcode.com/problems/count-days-without-meetings/) | Medium | Solved |
3131
| March 25 | [3394. Check if Grid can be Cut into Sections](https://leetcode.com/problems/check-if-grid-can-be-cut-into-sections/) | Medium | Solved |
3232
| March 26 | [2033. Minimum Operations to Make a Uni-Value Grid](https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/) | Medium | Solved |
33-
| March 27 | []() | | |
33+
| March 27 | [2780. Minimum Index of a Valid Split](https://leetcode.com/problems/minimum-index-of-a-valid-split/) | Medium | Unsolved |
3434
| March 28 | []() | | |
3535
| March 29 | []() | | |
3636
| March 30 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
44-
| Medium | 19 | 9 | 10 |
44+
| Medium | 20 | 9 | 11 |
4545
| Hard | 1 | 0 | 1 |

0 commit comments

Comments
 (0)