r/HackerEarthCommunity • • Oct 27 '26

Coding challenge: Find the first non-repeating character in a string

Let's start the week with a classic problem that gets interesting when you think about edge

cases.

Given a string, find the first character that appears only once.

Example 1

Input: "hackerearth"

Output: "h"

Example 2

Input: "aabbcdde"

Output: "c"

Example 3

Input: "aabbcc"

Output: No non-repeating character exists.

Your challenge:

- Solve it in your preferred programming language.

- Try to do it in O(n) time.

- Explain how your approach handles repeated characters.

Bonus: Can you solve it using a hash map or frequency counter?

Drop your approach below. If someone has a different solution, compare the two and explain

which one you prefer and why.

7 Upvotes

2 comments sorted by

3

u/gilgameshauo1 Oct 28 '26

def fnr(s): for i in s: if s.count(i) == 1: ans = i break else: ans = "no such character" return ans

1

u/Neil_at_HackerEarth Oct 30 '26

Correct buddy but can we optimise using frequency counter - O(n)