First Unique Character in a String Problem Statement

Given a string STR consisting of lowercase English letters, identify the first non-repeating character in the string and return it. If no such character exists, return '#'.

Input:

The first line consists of an integer T representing the number of test cases.
For each test case, there is a single line consisting of a string STR containing only lowercase English letters.

Output:

For each test case, output the first non-repeating character in the given string.
Output each result on a new line.

Example:

Input:

2
abcab
aabbcc

Output:

c
#
Explanation:

For the first test case, 'c' is the first non-repeating character in 'abcab'.
For the second test case, there is no non-repeating character in 'aabbcc', hence the output is '#'.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 10^4

Where T denotes the number of test cases, and N represents the length of the string. The time limit for each test case process is 1 second.

Note:
No need to print anything; just implement the function to return the result.
AnswerBot
3d

Identify the first non-repeating character in a given string and return it, or '#' if none exists.

  • Iterate through the string to count the frequency of each character

  • Iterate through the string again to...read more

Help your peers!
Add answer anonymously...
Amdocs Associate 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