Skip to content

Commit 6e92b7e

Browse files
committed
Runtime: 310 ms (Top 93.88%) | Memory: 61.5 MB (Top 78.57%)
1 parent 99fb004 commit 6e92b7e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 310 ms (Top 93.88%) | Memory: 61.5 MB (Top 78.57%)
12
class Solution {
23
public:
34
bool checkinvalid( int a, int b, vector<vector<int>>& languages){ //helper func., checks if a and b can communicate or not
@@ -7,18 +8,18 @@ class Solution {
78
}
89
return true;
910
}
10-
11-
int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {
11+
12+
int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {
1213
int m= languages.size();
1314
vector<vector<int>> g(m+1, vector<int>(0)); // graph to store adjacency list with people as nodes & friendships as edges
1415
// create graph
1516
for( int i=0;i<friendships.size();i++){
1617
g[friendships[i][0]].push_back(friendships[i][1]);
1718
g[friendships[i][1]].push_back(friendships[i][0]);
1819
}
19-
20+
2021
vector<int> voters(m+1,0); // to store people who cant communicate with atleast a friend
21-
int voterscount=0;
22+
int voterscount=0;
2223
for( int i=1;i<m+1;i++){
2324
for( int j=0;j<g[i].size();j++){
2425
if( checkinvalid(i, g[i][j], languages)){ // ith can vote
@@ -28,14 +29,14 @@ class Solution {
2829
}
2930
}
3031
}
31-
unordered_map<int,int> mappy; // language -> votes
32-
int maxvotes=0;
33-
32+
unordered_map<int,int> mappy; // language -> votes
33+
int maxvotes=0;
34+
3435
for( int i=1;i<m+1;i++){
35-
if(voters[i]==1){
36+
if(voters[i]==1){
3637
for( int j: languages[i-1]){
3738
mappy[j]++;
38-
39+
3940
if(maxvotes<mappy[j]){
4041
maxvotes= mappy[j];
4142
}
@@ -44,4 +45,4 @@ class Solution {
4445
}
4546
return voterscount - maxvotes; // # who need to be taught the language
4647
}
47-
};
48+
};

0 commit comments

Comments
 (0)