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
20 changes: 16 additions & 4 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ def max_sub_array(nums):
Time Complexity: ?
Space Complexity: ?
"""
if nums == None:
if nums == None or len(nums) == 0:
return 0
if len(nums) == 0:
return 0
pass

if len(nums) == 1:
return nums[0]

max_sum = nums[0] + nums[1]
max_sum_here = 0

for i in range(len(nums)):
max_sum_here = max_sum_here + nums[i]
if max_sum < max_sum_here:
max_sum = max_sum_here
if max_sum_here < 0:
max_sum_here = 0
Comment on lines +18 to +22

Choose a reason for hiding this comment

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

This works, but you can simplify it a bit using the max function.


return max_sum
24 changes: 21 additions & 3 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@
# Space Complexity: ?
def newman_conway(num):
""" Returns a list of the Newman Conway numbers for the given value.
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n)
Space Complexity: O(n)
"""
Comment on lines 5 to 9

Choose a reason for hiding this comment

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

👍

pass
if num < 1:
raise ValueError("Input must be an integer larger than 0")

if num == 1:
return "1"

seq = [1, 1]
i = 3

while i <= num:
n = seq[seq[i - 2] - 1] + seq[i - seq[i - 2] - 1]
seq.append(n)
i += 1

printed_seq = ""
for n in seq:
printed_seq += str(n) + " "

return printed_seq[0:-1]