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
16 changes: 13 additions & 3 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
def max_sub_array(nums):
""" Returns the max subarray of the given list of numbers.
Returns 0 if nums is None or an empty list.
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n)
Space Complexity: O(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""

if nums == None:
return 0
if len(nums) == 0:
return 0
pass

max_sum = nums[0]
temp_sum = nums[0]

for i in range(1, len(nums)):
current = nums[i]
temp_sum = max(current, current + temp_sum)
max_sum = max(temp_sum, max_sum)

return max_sum
22 changes: 21 additions & 1 deletion lib/newman_conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,24 @@ def newman_conway(num):
Time Complexity: ?
Space Complexity: ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 Looks good, but time and space complexity?

"""
pass
# P(n) = P(P(n - 1)) + P(n - P(n - 1)) - Newman Conway Sequence
if num == 0:
raise ValueError()

if num == 1:
return "1"
if num == 2:
return "1 1"
starter_arr = [0, 1, 1]

i = 3
while i <= num:
starter_arr.append(
starter_arr[starter_arr[i-1]] + starter_arr[i - starter_arr[i-1]])
i += 1

newman_string = ""
for i in range(1, len(starter_arr)):
newman_string += str(starter_arr[i]) + " "

return newman_string[:-1]