-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGooglePracticeQ2.cpp
More file actions
54 lines (54 loc) · 1.32 KB
/
GooglePracticeQ2.cpp
File metadata and controls
54 lines (54 loc) · 1.32 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
#include<bits/stdc++.h>
using namespace std;
int smallestCharCount(string x){
int countArr[26] = {0};
for(int i=0;i<x.size();i++){
countArr[(int)x[i] - 97] +=1;
}
for(int i = 0;i<26;i++){
if(countArr[i]>0) return countArr[i];
}
}
vector<int> computefn(vector<string> A,vector<string> B){
vector<int> Amin;
vector<int> Bmin;
for(auto x : A){
int n = smallestCharCount(x);
Amin.push_back(n);
}
for(auto x : B){
int n = smallestCharCount(x);
Bmin.push_back(n);
}
vector<int> finalArr;
for(auto x : Bmin){
int temp = 0;
for(auto y : Amin){
if(x>y) temp++;
}
finalArr.push_back(temp);
}
return finalArr;
}
vector<string> splitter(string A){
string temp = "";
vector<string> Astr;
for(int i=0;i<A.size()+1;i++){
if(A[i]==',' || A[i]==' ' || i== A.size()){
Astr.push_back(temp);
temp = "";
}else{
temp+=A[i];
}
}
return Astr;
}
int main(){
string A = "abcd,aabc,bd";
string B = "aaa,aa";
vector<string> Astr = splitter(A);
vector<string> Bstr = splitter(B);
vector<int> res = computefn(Astr,Bstr);
for(auto x : res) cout<<x<<" ";
return 0;
}