-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy path2365-Task-scheduler-ii.cpp
More file actions
32 lines (29 loc) · 777 Bytes
/
2365-Task-scheduler-ii.cpp
File metadata and controls
32 lines (29 loc) · 777 Bytes
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
class Solution {
public:
long long taskSchedulerII(vector<int>& tasks, int space) {
unordered_map<long long, long long>mapp;
long long res=tasks.size();
vector<long long>arr(tasks.size());
long long c=0;
for(int i=0;i<tasks.size();i++)
{
if(mapp.find(tasks[i])==mapp.end())
{
mapp[tasks[i]]=i;
c++;
arr[i]=c;
}
else
{
c++;
long long time=c-arr[mapp[tasks[i]]]-1;
long long x=0;
x=max(x,space-time);
c+=x;
arr[i]=c;
mapp[tasks[i]]=i;
}
}
return arr[tasks.size()-1];
}
};