Skip to content

Commit 4ad6ed8

Browse files
committedJan 5, 2025
Solve biweekly contest question 3
1 parent 9abae9e commit 4ad6ed8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <climits>
4+
#include <algorithm>
5+
#include <unordered_map>
6+
using namespace std;
7+
8+
int minimumSeconds(vector<int> &nums)
9+
{
10+
unordered_map<int, vector<int>> mp;
11+
for (int i = 0; i < nums.size(); i++)
12+
mp[nums[i]].push_back(i);
13+
14+
int ans = nums.size(), x = 0;
15+
16+
for (auto &k : mp)
17+
{
18+
x = k.second[0];
19+
int y = nums.size() - k.second.back() - 1;
20+
x += y;
21+
x = (x + 1) / 2;
22+
for (int i = 0; i < k.second.size() - 1; i++)
23+
x = max(x, (k.second[i + 1] - k.second[i]) / 2);
24+
ans = min(ans, x);
25+
}
26+
27+
return ans;
28+
}
29+
30+
int main(int argc, char const *argv[])
31+
{
32+
vector<int> nums = {2, 4, 6, 23, 34, 12, 233, 45553, 45795};
33+
int sec = minimumSeconds(nums);
34+
cout << sec << endl;
35+
return 0;
36+
}

0 commit comments

Comments
 (0)
Please sign in to comment.