Find First Unique Character in a String
You are given a string S
of length N
. Your task is to find the index (considering 1-based indexing) of the first unique character in the string. If there are no unique characters, return -1
.
Example:
Input:
T = 2
N = 5
S = "hello"
N = 4
S = "aabb"
Output:
1
-1
Explanation:
The first unique character in "hello" is 'h', which is at index 1. The string "aabb" has no unique characters.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10^4
Note:
A unique character in a string is one that appears only once.

AnswerBot
4mo
Find the index of the first unique character in a given string, return -1 if no unique characters are found.
Create a hashmap to store the frequency of each character in the string.
Iterate through the ...read more
Help your peers!
Add answer anonymously...
Amdocs Software Developer interview questions & answers
A Software Developer was asked 6mo agoQ. What are the key concepts of Object-Oriented Programming (OOP)?
A Software Developer was asked 6mo agoQ. What is the internal working mechanism of a HashMap?
A Software Developer was asked 8mo agoQ. What is SDLC and what are its types?
Popular interview questions of Software Developer
A Software Developer was asked 6mo agoQ1. What are the key concepts of Object-Oriented Programming (OOP)?
A Software Developer was asked 6mo agoQ2. What is the internal working mechanism of a HashMap?
A Software Developer was asked 8mo agoQ3. What is SDLC and what are its types?
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

