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

Determine if a string has all unique characters

Input : A string
Output : Boolean

Clarifications :

  • Is the input string ASCII or Unicode ?
    • If ASCII then we need storage size of 128 bits

Logic :

  • Iterate over entire string
  • If string size greater than 128 characters (total ASCII characters) then return false.
  • Iterate over the string one character at a time,
    • For each character find if there is another similar character in the string after it.
    • If there is one then return false
  • Else return true.

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 *