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
4mo

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!
Select
Add answer anonymously...

Tech Mahindra Software Engineer interview questions & answers

A Software Engineer was asked 1w agoQ. How do you train a machine?
A Software Engineer was asked 2mo agoQ. What is Kotlin?
A Software Engineer was asked 2mo agoQ. Tell me about your projects and training.

Popular interview questions of Software Engineer

A Software Engineer was asked 1w agoQ1. How do you train a machine?
A Software Engineer was asked 2w agoQ2. What are the key concepts of Object-Oriented Programming, and why are they used?
A Software Engineer was asked 2w agoQ3. What is the difference between String and StringBuilder, and in what circumstanc...read more

Top HR questions asked in Tech Mahindra Software Engineer

A Software Engineer was asked 4mo agoQ1. What is your salary expectation?
A Software Engineer was asked 5mo agoQ2. Are you willing to relocate?
A Software Engineer was asked 5mo agoQ3. Can you tell me about yourself?
Tech Mahindra Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits