-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask Scheduler.cpp
More file actions
59 lines (48 loc) · 1.02 KB
/
Task Scheduler.cpp
File metadata and controls
59 lines (48 loc) · 1.02 KB
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
54
55
56
57
58
59
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
int leastInterval(int n, int k, vector<char> &s) {
// code here
map<int,int> mp;
for(int i=0;i<n;i=i+1)
{
mp[s[i]-'A']++;
}
int mx=0;
for(int i=0;i<26;i=i+1)
{
if(mp[i]>mx)
{
mx=mp[i];
}
}
int c=0;
for(int i=0;i<26;i=i+1)
{
if(mp[i]==mx)
{
c=c+1;
}
}
int ans=mx+k*(mx-1)+c-1;
return max(ans,n);
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int N, K;
cin >> N >> K;
vector<char> tasks(N);
for (int i = 0; i < N; i++) cin >> tasks[i];
Solution obj;
cout << obj.leastInterval(N, K, tasks) << endl;
}
return 0;
}
// } Driver Code Ends