Problem Β· String
Find First Unique π
Learn this problemProblem statement
Amazon Web Services is experimenting with optimizing search queries based on the location of the first unique character in a search. You have been asked to help test the query your team has created to ensure it works as designed. A unique character is one which 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
findFirstUnique(s: String) β int
Complete the function findFirstUnique in the editor below.
findFirstUnique has the following parameter(s):
string s: a string
Returns
int: either the 1-based index or -1
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.
Constraints
1 <= len of s <= 105The string s consists of lowercase English letters only.More Amazon problems
- Secure Maximum DeliveriesOA Β· Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW Β· Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN Β· Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN Β· Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW Β· Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW Β· Seen Jul 2026
- Maximum System Memory CapacityOA Β· Seen Jul 2026
- Package Delivery SystemOA Β· Seen Jul 2026