Skip to content

Commit 8725259

Browse files
Add files via upload
1 parent c38d1ed commit 8725259

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the
2+
numbers of occurrences of other characters in the string.
3+
4+
-------------------------------------------------
5+
6+
In other words, check if frequency(c) = length/2, for any c in the array
7+
8+
9+
To be more precise, 2*frequency(c) = length, because if there are 2n+1 characters and 1 occurs n times, it does not satisfy the statement.
10+
11+
char string[MAX_LENGTH], frequency[NO_OF_ALPHABETS] = {0};
12+
int max_frequency = 0, i, length;
13+
14+
scanf("%s", string);
15+
16+
for(i = 0; string[i] != '\0'; i++)
17+
frequency[string[i] - 'a']++;
18+
19+
length = i;
20+
21+
for(i = 0; i < NO_OF_ALPHABETS; i++)
22+
max_frequency = max(max_frequency, frequency[i]);
23+
24+
25+
26+
printf("%s\n", (2*max_frequency == length ? "YES" : "NO") );

0 commit comments

Comments
 (0)