Help me in solving SPSBTR problem

My issue

Could this be an alternative solution to the given question ?

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
    int T;
    cin >> T;
    while(T--)
    {
        int length;
        cin >> length;
        string word;
        cin >> word;
        int frequency[27]={0};
        for(int i = 0; i < length; i++)
            frequency[(word[i]-'a') + 1]++;
        int count = 0;
        for(int i = 1; i<27; i++)
        {
            if(frequency[i] == 0)
                continue;
            if(frequency[i] >= i)
                count += i;
            else if(frequency[i] < i)
                count += frequency[i];
        }
        cout << count << endl;
    }
}

Learning course: Two pointers
Problem Link: Special Substring Practice Problem in - CodeChef

Also, when I try using the “Debug my code” feature, I get the following test cases where my solution failed.
Input :
1
1
a
Your Output : 1
Expected Output :
52
41
36
55
24
5
23
48
9
35
67
15
15
59
22
27
62
51
36
60
44
36
69
60
42
29
58
41
17
42
8
39
22
65
16
16
12
43
41
40
35
18
15
5
59
59
72
30
54
41
37
23
25
11
48
9
32
24
23
27
40
57
31
34
37
16
19
40
27
1
43
32
57
20
29
6
50
36
53
28
52
36
83
55
54
48
23
31
5
8
58
10
58
22
49
41
16
40
25
76
18
80
25
39
50
26
37
44
43
5
10
22
14
49
77
46
42
64
42
32
42
23
28
33
31
1
43
64
13
56
46
32
41
4
51
35
26
31
34
38
57
32
63
44
99
1
30
55
39
44
48
10
19
39
51
38
9
25
46
11
6
3
47
46
33
45
16
25
42
58
12
32
23
21
49
21
19
77
30
58
28
26
50
59
45
13
9
77
66
29
11
58
55
35
42
51
62
27
27
62
63
50
7
44
34
21
28
35
20
44
70
60
57
39
57
25
56
40
36
28
66
51
6
33
40
38
58
33
42
7
28
45
42
44
35
40
33
11
41
62
23
5
51
18
58
37
83
32
17
27
42
23
36
27
25
1
26
23
55
48
36
3
51
22
28
56
24
78
10
14
49
83
42
29
20
29
24
38
44
25
13
59
10
32
37
75
40
45
36
35
39
58
49
48
11
26
36
23
45
23
60
39
51
12
41
55
3
36
17
57
26
30
35
72
40
66
52
33
60
16
35
43
39
27
47
40
16
12
25
45
23
42
49
22
34
52
52
12
45
36
2…