Skip to content

mvp #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

mvp #413

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions names/binary_search_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None

def insert(self, value):
if value < self.value:
if self.left is None:
self.left = Node(value)
else:
self.left.insert(value)
else:
if self.right is None:
self.right = Node(value)
else:
self.right.insert(value)

def contains(self, value):
if self.value == value:
return True
if value < self.value:
if not self.left:
return False
else:
return self.left.contains(value)
else:
if not self.right:
return False
else:
return self.right.contains(value)
17 changes: 12 additions & 5 deletions names/names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from binary_search_tree import Node

start_time = time.time()

Expand All @@ -13,10 +14,16 @@
duplicates = [] # Return the list of duplicates in this data structure

# Replace the nested for loops below with your improvements
for name_1 in names_1:
for name_2 in names_2:
if name_1 == name_2:
duplicates.append(name_1)
# for name_1 in names_1:
# for name_2 in names_2:
# if name_1 == name_2:
# duplicates.append(name_1)
search_tree = Node("None")
for name in names_1:
search_tree.insert(name)
for name in names_2:
if search_tree.contains(name):
duplicates.append(name)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
Expand All @@ -25,4 +32,4 @@
# ---------- Stretch Goal -----------
# Python has built-in tools that allow for a very efficient approach to this problem
# What's the best time you can accomplish? Thare are no restrictions on techniques or data
# structures, but you may not import any additional libraries that you did not write yourself.
# structures, but you may not import any additional libraries that you did not write yourself.
10 changes: 9 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ def contains(self, value):
return False

def reverse_list(self, node, prev):
pass
self.prev = None
current = self.head

while current is not None:
next_node = current.next_node
current.next_node = prev
prev = current
current = next_node
self.head = prev
12 changes: 9 additions & 3 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
class RingBuffer:
def __init__(self, capacity):
pass
self.capacity = capacity
self.storage = []
self.curr = 0

def append(self, item):
pass
if len(self.storage) == self.capacity:
self.storage[self.curr] = item
self.curr = (self.curr + 1) % self.capacity
else:
self.storage.append(item)

def get(self):
pass
return self.storage