First Non-Repeating Character
First Non-Repeating Character
Given a string s, find the first character that appears exactly once, reading left to right. If no such character exists, print -1. Your solve(...) function receives these inputs directly as ready-made arguments — no input reading or parsing needed. Just compute and return the answer. Example: "Flycodx" → 'l' (F appears once, l appears once — 'l' is not first; actually: F=1,l=1,y=1,c=1,o=1,d=1,x=1, so 'F' first but case matters) Note: treat uppercase and lowercase as distinct characters.
Input format — only if your code reads from stdin
Input format (stdin): - A single string s Output: the first non-repeating character, or -1 if all characters repeat.
Approach
Two-pass approach: first pass builds a frequency map counting each character's occurrences. Second pass returns the first character with a count of exactly 1.
Input
Output
- •
1 ≤ len(s) ≤ 10^5, s contains printable ASCII characters
More Hash Maps problems
Browse all coding problems →Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards