Inspiration

As part of MLH Global Hack Week - Career, I wanted to tackle a problem commonly seen in technical interviews: finding the first non-repeating character in a string. Since this question tests foundational problem-solving skills and efficient data manipulation, it was an ideal choice to refine my skills for future software and ML roles.

What it does

The program identifies the first non-repeating character in a given string. If all characters repeat or the string is empty, the program returns None. This utility can be crucial in text-processing applications where unique elements need to be quickly located.

How I built it

  • Data Structure Selection: Using a dictionary, we stored each character’s frequency.
  • Algorithm:
    1. Pass 1: Count each character’s occurrences.
    2. Pass 2: Find the first character with a count of 1.

Challenges I ran into

  • Efficiency: An initial nested loop approach had O(n²) time complexity, which was slow for large strings. Switching to a dictionary reduced it to O(n).
  • Edge Cases: Ensuring robust handling for cases like strings with all repeating characters or empty strings was crucial.

Accomplishments that I'm proud of

I’m proud of optimizing the solution for efficiency and handling edge cases gracefully. Completing this project as part of MLH Global Hack Week - Career added to the sense of accomplishment.

What I learned

  • Using dictionaries for quick lookups and data storage.
  • Importance of time complexity in optimizing solutions.
  • Handling edge cases to make solutions robust for various inputs.

What's next for Find the First Non-Repeating Character in a String.

I’m interested in expanding this project to cover additional variations, like returning the position of non-repeating characters or even handling multiple strings at once. Applying this to real-world data, like analyzing text uniqueness across documents, could also be a great future extension.

Built With

Share this project:

Updates