Problem · String
First Unique Character (Data & Analytics)
Learn this problemProblem statement
A unique character is one that appears only once in a string. Given a string consisting of lowercase English letters only, return the index of the first occurrence of a unique character in the string using 1-based indexing. If the string does not contain any unique character, return -1.
Function
getUniqueCharacter(s: String) → int
Complete the function getUniqueCharacter in the editor below.
getUniqueCharacter has the following parameter(s):
string s: a string
Returns
int: either the 1-based index or -1
✎ᝰ.Credit to chizzy_elect ᝰ.ᐟ 🧡˚
Examples
Example 1
s = "statistics"return = 3The unique characters are [a, c] among which a occurs first. Using 1-based indexing, it is at index 3.
Example 2
s = "hackthegame"return = 3The unique characters are [c, k, t, g, m] out of which the character c occurs first, at index 3 :)
Constraints
- 1 ≤ length of s ≤ 10^5
- The string s consists of lowercase English letters only.
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025