Close
Topic list
First unique character in a string
MEDIUM
15 mins
Strings
Topics (Covered in this problem)
Problem solved
Skill meter
Strings
-
-
Other topics
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# First unique character in a string

Contributed by
Dhruv Sharma
Medium
0/80
Avg time to solve 15 mins
Success Rate 85 %
Share

## Problem Statement

#### Note

``````A unique character in a string is the character that appears only once in the string. For example, ‘h’, ‘e’, and ‘o’ are the unique characters in the string “hello”.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
16
codingninjascode
24
practicepracticepractice
``````
##### Sample Output 1:
``````6
-1
``````
##### Explanation for Input 1:
``````For the first subtask the explanation is given in the problem statement.

For the second subtask there are no unique characters so ans is -1.
``````
##### Sample Input 2 :
``````3
19
palindromemordnilap
9
notunique
7
caaabbc
``````
##### Sample Output 2:
``````10
2
-1
``````
##### Explanation for Input 2:
``````For the first subtask, every character except ‘e’ occurs 2 times so we print the index of e that is 10.

For the second subtask, the characters ‘o’ , ‘t’ , ‘e’ , ‘i’ and ‘q’ are unique but ‘o’ occurs before all the other unique characters .

For the third subtask, all the characters are not unique so we return -1.
``````
Auto
Console