forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
47 lines (38 loc) · 1 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
//stringConstruction
/*
In this question we need to find letters number of unique letters because we can use substring of any length
*/
#include <bits/stdc++.h>
using namespace std;
int stringConstruction(string s) {
//For storing the unique elements
int arr[26];
//assigning all indexes of above array to zero
memset(arr,0,sizeof(arr));
for(int i=0; i<s.length(); i++){
//if we encounter any new array we will increase that index to zero
if(arr[s[i]-97]==0){
arr[s[i]-97]++;
}
}
int count=0; // For storing the number of unique elements in string
for(int i=0; i<26; i++){
//If array index is 1 means this element is present in string
if(arr[i]==1){
count++;
}
}
return count;
}
int main()
{
int q;
cin >> q;
for (int q_itr = 0; q_itr < q; q_itr++) {
string s;
cin>>s;
int result = stringConstruction(s);
cout << result << "\n";
}
return 0;
}