-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
53 lines (42 loc) · 995 Bytes
/
Test.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Mock Test - Amazon
#include <bits/stdc++.h>
using namespace std ;
int findMaxZeroes(vector<int> arr) {
int n = arr.size();
vector<int> leftMin(n);
int mini = INT_MAX;
for(int i = 0; i < n; ++i) {
mini = min(arr[i], mini);
leftMin[i] = mini;
}
int count = 0;
for(int i = 0; i < n; ++i) {
count += (arr[i] == leftMin[i]);
}
return count;
}
int getOutlierValue(vector<int> arr) {
map<int, int> mp;
int sum = 0;
int sol = 0;
for(int i=0; i<arr.size(); i++){
sum += arr[i];
mp[arr[i]]++;
}
for(int i=0; i<arr.size(); i++)
{
if(mp.find((sum-arr[i])/2)!=mp.end() && arr[i]!=(sum-arr[i])/2 && (sum-arr[i])%2==0) sol = max(sol, arr[i]);
}
return sol;
}
auto init = []() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 'c';
}();
int main () {
vector<int> arr = {4,1,2,1, 10, 3};
cout << getOutlierValue(arr);
return 0;
}