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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
18 changes: 15 additions & 3 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
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)
Comment on lines 2 to +6

Choose a reason for hiding this comment

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

👍 Nice work

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

max_so_far = 0
max_ending_here = 0

for num in nums:
max_ending_here = max_ending_here + num
if max_so_far < max_ending_here:
max_so_far = max_ending_here

if max_so_far <= 0:
return max(nums)

return max_so_far
24 changes: 18 additions & 6 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@


# Time complexity: ?
# Space Complexity: ?
# Time complexity: O(n)
# Space Complexity: O(n)
def newman_conway(num):
Comment on lines +3 to 5

Choose a reason for hiding this comment

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

👍

""" Returns a list of the Newman Conway numbers for the given value.
Time Complexity: ?
Space Complexity: ?
""" Returns a string of the Newman Conway numbers for the given value.
Time Complexity: O(n)
Space Complexity: O(n)
"""
pass
if num == 0:
raise ValueError

if num == 1:
return "1"

seq = [0, 1, 1]

for i in range(3, num + 1):
next_num = seq[seq[i-1]] + seq[i - seq[i-1]]
seq.append(next_num)

return ' '.join([str(n) for n in seq[1:num+1]])