LIVE Coding Round: Find the first duplicate character in the string/array.
Utilisateur anonyme
1. If you're given a string - check for edge cases (string empty, null etc.) 2. Create a HashMap to store character and its count (number of times it appears in a string) 3. Loop through the string and for each character add/update its character count in the map. 4. Loop ends 5. Now loop through the string again, and for each character, get its count from the map. 6. If count > 1, then return this character. Complexity - O(n + n) = O(n)