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.
Be the first one to answer
Add answer anonymously...
Top Amdocs Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amdocs Software Developer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app