Character Frequency in Order of Occurrence

For the given string S of length N, determine the frequency of each character from 'a' to 'z' appearing within S.

Input:

The first input line contains an integer 'T' representing the number of test cases. Each subsequent line for each test case contains the string 'S'.

Output:

For each test case, output a single line with 26 space-separated integers, each indicating the frequency of the corresponding character from 'a' to 'z'.

Example:

Input:
S = "abcdg"
Output:
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

Constraints:

  • 1 <= T <= 10^2
  • 1 <= |S| <= 10^4
  • All characters in the string are lowercase English alphabets.
  • Time Limit: 1 second

Note:

No need to handle I/O, only function implementation is required.
AnswerBot
2d

The task is to determine the frequency of each character from 'a' to 'z' in a given string.

  • Create an array of size 26 to store the frequency of each character from 'a' to 'z'.

  • Iterate through the input...read more

Help your peers!
Add answer anonymously...
Tech Mahindra Software Engineer 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

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