FazeelUsmani / Amazon-SDE-Preparation

This repository includes all the interview preparation questions for Amazon SDE role
https://practice.geeksforgeeks.org/batch/Amazon-Test-Series
1.15k stars 295 forks source link

Create 07 firstNonRepeatingCharacter.cpp #64

Closed Juro221 closed 3 years ago

Juro221 commented 3 years ago

We use unordered_map for hashing. Firstly we just iterate through string and we save in our map how many times we saw each char. Then we iterate again through a string and we if find some char which value in map is 1, we return that char. If we didnt find any we return -1. Time complexity is O(|S|), where S is our string on input.