Find index of first unique character
SnapchatSoftware Engineer · Technical ScreenLast updated
Find index of first unique character evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Given a string s, return the index of the first character that appears exactly once; if none exists, return -1. Assume s may include both lowercase and uppercase English letters. Clarify whether the check is case-sensitive and implement both case-sensitive and case-insensitive variants. Follow-ups: (
- Optimize for a small fixed alphabet—can you use constant extra space? (
- How would you support full Unicode, including grapheme clusters and normalization issues? (
- If s arrives as a stream too large for memory, how would you detect the first unique character online? Analyze time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.