Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper - Nandita G. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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 +5 to +6

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
if len(nums) == 1:
return nums[0]

max_so_far = nums[0]
max_ending_here = 0

for i in range(len(nums)):
if max_ending_here < 0:
max_ending_here = 0
Comment on lines +19 to +20

Choose a reason for hiding this comment

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

Just a note that you can use the max function as well.

max_ending_here += nums[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
return max_so_far
25 changes: 20 additions & 5 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@


# Time complexity: ?
# Space Complexity: ?
# Time complexity: O(n)
# Space Complexity: O(n)
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 +3 to +8

Choose a reason for hiding this comment

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

👍 Nicely done.

"""
pass
if num <= 0:
raise ValueError("num cannot be less than 1")
memo = [0] * (num+1)
memo[0] = 0
memo[1] = 1
if num > 1:
memo[2] = 1

x = 3
while x <= num:
memo[x] = memo[memo[x - 1]] + memo[x - memo[x - 1]]
x += 1

memo.pop(0)
memo = [str(int) for int in memo]
return " ".join(memo)