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: nullfirstNonRepeatingChar("TechBlitz"); // Expected output: "T"firstNonRepeatingChar("stress"); // Expected output: "t"
Did you know?
JavaScript was created in 10 days in May 1995.
Test Cases
Input:
"aabbccdde"
Expected Output:
"e"