ExamAdda Logo

First Non Repeating Character

Easy

Given a string s, find the first character that appears exactly once in the string.

Return that character as a string. If every character appears more than once, return "-1".

The search must follow the original order of characters in the string.

Example 1

Input

s = "swiss"

Output

w

Explanation

The character s appears multiple times. The character w appears only once and is the first non-repeating character.

Example 2

Input

s = "aabbcc"

Output

-1

Explanation

Every character appears more than once, so there is no non-repeating character.

Constraints

1 <= s.length <= 10^5
s consists of lowercase English letters.

Hints:

Hint 1

Count how many times each character appears in the string.

Author & Technical Reviewer

Chatla Jithin Sri Surya

Written by: Chatla Jithin Sri Surya

<p>IIEST Shibpur | SDE | AI, ML &amp; Gen AI | DSA | Building Intelligent, Scalable Software</p>

Chatla Jithin Sri Surya

Technically reviewed by: Chatla Jithin Sri Surya

<p>IIEST Shibpur | SDE | AI, ML &amp; Gen AI | DSA | Building Intelligent, Scalable Software</p>

Published

Nov 7, 2026

Last updated

Nov 7, 2026

Last technically reviewed

Nov 7, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output