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": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
17 changes: 14 additions & 3 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
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(n)
"""
Comment on lines 2 to 7

Choose a reason for hiding this comment

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

👍 The space complexity here is O(1) because you're not building a new list.

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

for i in range(len(nums)):
current_sum = max((nums[i] + current_sum), nums[i])
max_sum = max(current_sum, max_sum)
if max_sum <=0:
return max(nums)

return max_sum


17 changes: 14 additions & 3 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
# 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 ==0:
raise ValueError

if num == 1:
return '1'

p = [0,1,1]

for i in range(3, num+1):
sum = p[p[i - 1]] + p[i - p[i - 1]]
p.append(sum)
return ' '.join(str(elem) for elem in p[1:])