Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Algorithm: find unique characters in a string using javascript

Problem :

Given a string find all the unique characters in the stirng.

Input : A string
Output : A string

Logic :

  • Iterate over entire string and create a frequency map
  • If the character occurs for the first time then set its value to 1
  • Else set its value to -1.
  • return a string with characters whose frequency was 1 in the frequency map.

Time complexity : O(n) ; where n is the string length
Space complexity : O(1) ; constant

Solution :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *