REPUB - Editorial

PROBLEM LINK:

Practice

Contest

Author: Ranjan Kumar Singh

Tester: Ved Prakash

Editorialist: Sudipto Roy

DIFFICULTY:

CAKEWALK

PRE-REQUISITES:

Arrays

PROBLEM:

To find the alphabet with the heighest frequency.

EXPLANATION:

For the given string, first check if the string has capital alphabet or small alphabet. Increment the frequency array according to what alphabet is found.

Pseudo Code:

for i=1 to 26:
    count[i]=0    //counting frequency
for i=1 to l(length of string):
    if(str[i] is lower alphabet) count[str[i]-'a']++;
    else if(str[i] is capital alphabet) count[str[i]-'A']++;   //selecting heighest frequency
max_freq=0
for i=1 to 26:
    if(count[i]>=max_freq) max=count[i],index=i

Complexity: O(N).

SOLUTIONS:

Setter’s solution

Tester’s solution

1 Like