Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Note: Write a solution that only iterates over the string once and uses O(1) additional memory, since this is what you would be asked to do during a real interview.
  2.  
  3. Given a string s consisting of small English letters, find and return the first instance of a non-repeating character in it. If there is no such character, return '_'.
  4.  
  5. Example
  6.  
  7. For s = "abacabad", the output should be
  8. firstNotRepeatingCharacter(s) = 'c'.
  9.  
  10. There are 2 non-repeating characters in the string: 'c' and 'd'. Return c since it appears in the string first.
  11.  
  12. For s = "abacabaabacaba", the output should be
  13. firstNotRepeatingCharacter(s) = '_'.
  14.  
  15. There are no characters in this string that do not repeat.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement