-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_A_Perfectly_Balanced_String.cpp
More file actions
67 lines (52 loc) · 1.13 KB
/
Copy pathB_A_Perfectly_Balanced_String.cpp
File metadata and controls
67 lines (52 loc) · 1.13 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
55
56
57
58
59
60
61
62
63
64
65
/*
Notes:
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
void solve() {
}
int main() {
fastio;
int t;
cin >> t;
while (t--) {
string str;
cin>>str;
int n = str.size();
queue<int> qs;
vector<int> check(26 , 0);
int i = 0;
//cout<<"periodic till here ";
while(i<n){
if(check[str[i] -'a']==0){
qs.push(str[i] - 'a');
// cout<<str[i]<<" ";
check[str[i] - 'a']++;
}
else break;
i++;
}
//cout<<endl;
string ans = "YES";
while(i<n){
if(qs.front()!=(str[i]-'a')){
ans = "NO";
break;
}
// cout<<str[i]<<" ";
qs.pop();
qs.push(str[i] - 'a');
i++;
}
cout<<ans;
cout<<endl;
}
return 0;
}