-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsequence.cpp
More file actions
41 lines (38 loc) · 891 Bytes
/
subsequence.cpp
File metadata and controls
41 lines (38 loc) · 891 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
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
string subsequenceAgain(string s, int k) {
// Complete this function
unordered_map <char, int> sol;
for(int i = 0; i < s.size(); i++){
if(sol.find(s.at(i)) == sol.end()){
sol.insert(make_pair<char, int> ((char)s.at(i), 1));
}
else{
sol[s.at(i)] = sol[s.at(i)] + 1;
}
}
for(int i = 0; i < s.size(); i++){
if(sol[s.at(i)] < k){
sol.erase(s.at(i));
}
}
string res = "";
for(int i = 0; i < s.size(); i++){
if(sol.find(s.at(i))!= sol.end()){
res = res + s[i];
}
}
return res;
}
int main() {
string s;
cin >> s;
int k;
cin >> k;
string result = subsequenceAgain(s, k);
cout << result << endl;
return 0;
}