Practice/Goldman Sachs/Leetcode 387. First Unique Character in a String
CodingOptional
Given a string, find the index of the first character that appears exactly once in the string. If no such character exists, return -1.
Your task is to identify the leftmost character in the string that has no duplicates anywhere else in the string.
Example 1:
Input: s = "programming" Output: 0 Explanation: The character 'p' appears only once and is at index 0
Example 2:
Input: s = "aabbccdd" Output: -1 Explanation: Every character appears exactly twice, so there is no unique character
Example 3:
Input: s = "xyzzyx" Output: -1 Explanation: All characters appear more than once
Example 4:
Input: s = "statistics" Output: 3 Explanation: The character 't' at index 3 is the first character that appears only once