Skip to content

Instantly share code, notes, and snippets.

View shaunhyp57's full-sized avatar

Shauna Hyppolite shaunhyp57

  • Atlanta, GA
View GitHub Profile
'''
Cracking The Coding Interview:
Ch 1 Arrays and Strings:
Q1 - Is Unique
"Implement an algorithm to determine if a string has all unique characters.
What if you cannot use additional data structures?"
Solutions: Time Complexity:
Brute Force O(n^2)
Dictionary O(n)
@shaunhyp57
shaunhyp57 / ch101-is_unique-no_ds.py
Last active July 13, 2020 05:40
Cracking the Coding Interview, 6th Ed., Chapter 1 Question 1: Is Unique - using no data structure, python solution
def no_ds_is_unique(input_string):
letters = 'abcdefghijklmnopqrstuvwxyz'
for c in input_string:
if c in letters:
letters = letters.replace(c, "")
else:
return False
return True
@shaunhyp57
shaunhyp57 / ch101-is_unique-set.py
Last active July 13, 2020 05:41
Cracking the Coding Interview, 6th Ed., Chapter 1 Question 1: Is Unique - using sets, python solution
def set_is_unique(input_string):
if len(set(input_string)) == len(input_string):
return True
return False
@shaunhyp57
shaunhyp57 / ch101-is_unique-dictionary.py
Last active July 13, 2020 05:41
Cracking the Coding Interview, 6th Ed., Chapter 1 Question 1: Is Unique - using dictionaries, python solution
# using dictionary
# complexity:
# time - O(n)
# space - O(n)
def dict_is_unique(input_string):
unique = {}
for c in input_string:
if c in unique:
@shaunhyp57
shaunhyp57 / ch101-is_unique-naive.py
Last active July 13, 2020 05:40
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