-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path2244.MinimumRoundsToCompleteAllTasks.cpp
More file actions
35 lines (26 loc) · 1.2 KB
/
2244.MinimumRoundsToCompleteAllTasks.cpp
File metadata and controls
35 lines (26 loc) · 1.2 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
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
int minimumRounds(vector<int>& tasks) {
map<int,int>mp; // map for storing all the job frequencies
for(auto x : tasks) // assinging the values in the map
{
mp[x]++;
}
int count=0; //initializin the count to zero for holding the rounds needed
for(auto x : mp) // itterating the map and performing the operation for the overall frequencies of the tasks
{
if(x.second==1)
return -1; // if the frequency is 1 then we return -1
if(x.second%3==0) // if the task frequency lies in 3x+2y and is divisible by 3 then y=0 to minimize count so we add count+=x.second/3 making y=0
{
count+=x.second/3;
}
else{ // else we take the stuff and divide it by 3 and add 1 to manage overall equation in terms of 2
count+=(x.second/3)+1;
}
}
return count; // returning the final count
}
};