Skip to content
Open
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
62 changes: 61 additions & 1 deletion rotate_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
# Add your clarifying questions here
# Will the value of shift_by always be positive?
# Yes, always a positive shift by
# Is the list always non-empty?
# An empty list will just return an empty
# Will the shift alway be to the right?
# Yes, we wil never shift to the left
# What if the shift_by is larger than our length?
# Shift by will be alwasy be less than the length
# let group decide
# Are we allowed to use built ins(pop, insert)?

# if there is only one element in the list, return the list?
# return None, shift out of bounds

# input : [1, 2, 3] , 2
# output: [2, 3, 1]\
#asssert rotate_list([1, 2, 3], 2) = [2, 3, 1]

# input: ['a', 'b', 'c', 'd'] , 1
# output": ['d','a','b', 'c']


# input = [9], 5233
# output: None, or shift out of bounds 

# Method 1
def rotate_list(list, shift_by):
pass
if not list:
return []
if len(list) < shift_by:
return f"shift_by {shift_by} is out of bounds"
if len(list) == 1:
return list

updated_list = [None] * len(list) # update_list = [None, None, None]

for i in range(len(list)):
if i + shift_by > len(list) - 1:
updated_list[i+shift_by-len(list)] = list[i]
continue
updated_list[i+shift_by] = list[i]

return updated_list

result = rotate_list(['a', 'b', 'c', 'd'] , 1)
print(result)

# Method 2 hard code, not add a new list!
def rotate_list(list, shift_by):
if not list:
return []
if len(list) < shift_by:
return f"shift_by {shift_by} is out of bounds"
if len(list) == 1:
return list

return list[(len(list) - shift_by): len(list)] + list[0: (len(list) - shift_by)]


# This also works
# return list[(len(list) - shift_by): ] + list[: (len(list) - shift_by)]
result = rotate_list([1, 2, 3] , 2)
print(result)
38 changes: 37 additions & 1 deletion skyline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
# Add your clarifying questions here
# Find smallest in the list, anythin above that is you could seens, order there is ascending order with no repeats

# Only one elemetn in the list? return None
# if the list if empty? return None
# if the elemenets are all the same? return None
# if the elements are not numbers? assume they are all numbers


# Given a list [-1, 1, 3, 7, 7, 3] determine which values could be "seen."
# The output should be: [1,3,7]


def skyline(building_list):
pass
if not building_list:
return None
if len(building_list) == 1:
return None

# bottom_floor = min(building_list, key=lambda element: element)
bottom_floor = min(building_list)
top_floor = max(building_list)

seen_list = []
previous_floor = float('-inf')

for floor in building_list:
# If it reaches the top floor, nothing else could be seen, exit the loop
if floor == top_floor:
seen_list.append(floor)
break
if (floor > bottom_floor) and (floor > previous_floor):
seen_list.append(floor)
previous_floor = floor

return seen_list


result = skyline([-1, 1, 3, 7, 7, 3])
print(result)