-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSherlock Valid String.cpp
More file actions
49 lines (46 loc) · 1.35 KB
/
Copy pathSherlock Valid String.cpp
File metadata and controls
49 lines (46 loc) · 1.35 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
#include <bits/stdc++.h>
using namespace std;
string isValid(string s)
{
map<char, int> d;
map<int, int> d2;
for (char a : s)
d[a]++;
for (auto i : d)
d2[i.second]++;
for (auto i : d2)
cout << i.first << " " << i.second << endl;
// for (auto i : d2)
// cout << i.first << " " << i.second << endl;
// for (auto i : d)
// cout << i.first << " " << i.second << endl;
// cout << d2.size() << " Size " << endl;
// cout << d2.begin()->second << " " << d2.rbegin()->second << endl;
if (d2.size() == 1)
return "YES";
else if (d2.size() == 2)
{
if ((d2.begin()->second == 1) && ((d2.begin()->first - d2.rbegin()->first == 1) || (d2.begin()->first == 1)))
return "YES";
else if ((d2.rbegin()->second == 1) && ((d2.rbegin()->first - d2.begin()->first == 1) || (d2.rbegin()->first == 1)))
return "YES";
else
return "NO";
}
else
return "NO";
}
int main()
{
string s;
getline(cin, s);
string result = isValid(s);
cout << result << "\n";
// cout << isValid(s);
// cout << isValid("abc") << endl;
// cout << isValid("abcc") << endl;
// cout << isValid("abccccc") << endl;
// cout << isValid("aabbccddeefghi") << endl;
// cout << isValid("abcdefghhgfedecba") << endl;
return 0;
}