AlgoDaily

Find First Non-Repeating Character

Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.

Description

You're given a string of random alphanumerical characters with a length between 0 and 1000.

Write a method to return the first character in the string that does not repeat itself later on.

So if we had a string input of "asdfsdafdasfjdfsafnnunl'", we can see there are multiple letters that are repeated.

Executing firstNonRepeat('asdfsdafdasfjdfsafnnunl') should return 'j' since it's the first letter where there is no duplicate.

Constraints
  • The given string can be empty
  • The string will only contain lowercase/uppercase alphabets and numerals
  • Expected time complexity : O(n)
  • Expected space complexity : O(A) where A is the number of ASCII characters
```js
function firstNonRepeat(str) {
  // fill this in
  return str;
};
```

CONTINUE WITH ALGODAILY PREMIUM

Keep going with the complete tutorial.

Unlock the remaining explanations and exercises, alongside the full learning library.

Explore Premium →
Open interactive view →