forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.cpp
58 lines (43 loc) · 1.13 KB
/
solution.cpp
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
#include <bits/stdc++.h>
using namespace std;
// Implementation Part
string gameOfThrones(string s) {
vector<int> freq(26, 0);
int index;
// counting frequency of each letters in string s
for(int i = 0; i < s.size(); i++){
index = s[i] - 'a';
freq[index]++;
}
if(s.size() % 2 == 0){
// if size of s is even then,
// frequency of each letter of s should be even
for(int i = 0; i < freq.size(); i++){
if(freq[i] % 2 != 0)
return "NO";
}
return "YES";
}else{
int count = 0;
// if size of s is odd, then
// there would one letter whose frequency should be odd
for(int i = 0; i < freq.size(); i++){
if(freq[i] % 2 != 0)
count++;
}
if(count > 1)
return "NO";
else
return "YES";
}
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string result = gameOfThrones(s);
fout << result << "\n";
fout.close();
return 0;
}