Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

First Unique Character

Data Structures, Operators & Stringsmedium

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 128: Working With Strings - Part 1

Implement `firstUnique(s)` returning the first character that appears exactly once, or an empty string if there is none.

Sample tests

Input: firstUnique("leetcode")
Output: "l"
Input: firstUnique("aabb")
Output: ""

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Returning early on the first unique-so-far before counting the whole string.

Learning resources

  • MDN: String
Approach & explanation (try first)

Two passes (count, then scan in order) find the first character that appears exactly once.

Loading...
⌘/Ctrl + Enter

Run your code to see results.