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 d4ba436 commit 152817fCopy full SHA for 152817f
problem-of-the-day/March/27_minIndexOfAValidSplit.cpp
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ public:
3
+ int minimumIndex(vector<int>& nums) {
4
+ int n = nums.size();
5
+ unordered_map<int, int> left_mp; // keep one element in the left map
6
+ unordered_map<int, int> right_mp; // populate the 1 to n-1 element in the right map
7
+ for(int i = 0; i < n; i++){
8
+ right_mp[nums[i]] += 1;
9
+ }
10
+
11
12
+ left_mp[nums[i]]++;
13
+ right_mp[nums[i]]--;
14
15
+ int n1 = i+1;
16
+ int n2 = n-i-1;
17
18
+ if(left_mp[nums[i]] > n1/2 && right_mp[nums[i]] > n2/2){
19
+ return i;
20
21
22
23
+ return -1;
24
25
+ };
0 commit comments