Count Frequency

You are given a string 'S' of length 'N', you need to find the frequency of each of the characters from ‘a’ to ‘z’ in the given string.

Example :

Given 'S' : abcdg
Then output will be : 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
Input Format :
The first line of the input contains an integer 'T' denoting the number of test cases.

The first and the only line of each test case contains the string 'S'.
Output Format :
The only line of output of each test case should contain 26 space-separated integers, where the 'i'th integer represents the frequency of the 'i'th character. 
Note :
You don’t have to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10^2
1 <= Length of the given string <= 10^4
It is guaranteed that all the characters in the string are lower case english alphabets.

Time Limit : 1 sec
CodingNinjas
author
2y
Count Frequency

Since there are just 26 lower case characters, we can use an array of size 26 to store the result.

Here is the algorithm :

  1. Create an array (say, ‘FREQ’), where 0-th index stores the fr...read more
Help your peers!
Add answer anonymously...
Bharti Airtel Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter