First Non-Repeating Character Problem Statement

You are given a string consisting of English alphabet characters. Your task is to identify and return the first character in the string that does not repeat. If every character repeats, return the first character of the string.

Input:

T (the number of test cases)
For each test case, a string consisting of English alphabet characters ('a' - 'z' and 'A' - 'Z').

Output:

For each test case, print the first non-repeating character in the string.
If no such character exists, print the first character of the string.

Example:

Input:
1
abcdabc
Output:
d

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ Length of Input String ≤ 104
Note:
You do not need to print anything; implement the function only.
Be the first one to answer
Add answer anonymously...
Persistent Systems 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