We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8f38541 commit bd93f3fCopy full SHA for bd93f3f
2780-minimum-index-of-a-valid-split.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+var minimumIndex = function(nums) {
6
+ let n = nums.length
7
+ if (n == 1) {
8
+ return -1
9
+ }
10
+ let mp = {}
11
+ let mx = 0
12
+ for (const num of nums) {
13
+ if(mp[num] == null) mp[num] = 0
14
+ mp[num]++
15
+ if (mp[num] > n/2) {
16
+ mx = num
17
18
19
+ let c = 0
20
+ for (let i = 0; i < n-1; i++) {
21
+ let num = nums[i]
22
+ if (num == mx) {
23
+ c++
24
25
+ if (c > (i+1)/2 && mp[mx]-c > (n-i-1)/2) {
26
+ return i
27
28
29
30
+};
0 commit comments