20. Non Repeating Character
The problem can be found at the following link: Question Link
My Approach
To find the first non-repeating character in a given string S
, I use an array cnt
of size 26 to count the occurrences of each character. I iterate through the string once to populate the cnt
array. Then, I traverse the string again to find the first character whose count is equal to 1, indicating it is non-repeating.
Time and Auxiliary Space Complexity
Time Complexity:
O(N)
, whereN
is the length of the input stringS
.Auxiliary Space Complexity:
O(1)
(constant space) since thecnt
array has a fixed size of26
, which does not depend on the input.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated