Katkat

Find index of first unique character

SnapchatSoftware Engineer · Technical Screen

Last 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: (

  1. Optimize for a small fixed alphabet—can you use constant extra space? (
  2. How would you support full Unicode, including grapheme clusters and normalization issues? (
  3. If s arrives as a stream too large for memory, how would you detect the first unique character online? Analyze time and space complexity.