Medium

Find the First Non-Repeating Character in a String

Description

Your task is to write a function that takes a string as input and returns the first non-repeating character in the string.

If all characters repeat, return 'null'.

This challenge is commonly used in text processing and algorithm design, such as:

  • Detecting unique elements in datasets.
  • Processing strings efficiently in search algorithms.
  • Implementing character frequency analysis in coding interviews.

Requirements

Input: A non-empty string consisting of lowercase and/or uppercase letters.
Output: - The first character that does not repeat in the string. Return 'null' if all characters are repeating.

Considerations

The function should be case-sensitive (i.e., 'a' and 'A' are different characters). The string may contain spaces or special characters. The solution should handle edge cases, such as strings with all identical characters.


Example Usage

firstNonRepeatingChar("programming"); // Expected output: "r"
firstNonRepeatingChar("aabbcc"); // Expected output: null
firstNonRepeatingChar("TechBlitz"); // Expected output: "T"
firstNonRepeatingChar("stress"); // Expected output: "t"

window code 2Test Cases

Input:

"aabbccdde"

Expected Output:

"e"