Skip to content

Instantly share code, notes, and snippets.

@shaunhyp57
Last active July 13, 2020 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunhyp57/8d481bb8f33b238e51f574b7b7b21d46 to your computer and use it in GitHub Desktop.
Save shaunhyp57/8d481bb8f33b238e51f574b7b7b21d46 to your computer and use it in GitHub Desktop.
Cracking the Coding Interview, 6th Ed., Chapter 1 Question 1: Is Unique - naive python solution
# naive solution
# complexity:
# time - O(n^2)
# space - O(1)
def naive_is_unique(input_string):
length = len(input_string)
if length < 2:
return True
for i, c in enumerate(input_string):
if i == length - 1:
break
for j in range(i+1, length):
if input_string[j] == c:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment