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--Andrea Palacios #42

Open
wants to merge 3 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
28 changes: 21 additions & 7 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#Time Complexity: O(n)
#Space Complexity: O(n)


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 5 to +10

Choose a reason for hiding this comment

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

👍 The space complexity is O(1) because you don't have a new collection.

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

max_so_far = nums[0]
max_ending_here = nums[0]

for i in range(1,len(nums)):
max_ending_here = max_ending_here + nums[i]
if(max_ending_here < 0):
max_ending_here = max(max_ending_here,nums[i])
if(max_so_far < max_ending_here):
max_so_far = max_ending_here

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


# Time complexity: ?
# Space Complexity: ?
def newman_conway(num):
""" Returns a list of the Newman Conway numbers for the given value.
Time Complexity: ?
Space Complexity: ?
"""
pass
'''
Time Complexity: O(n)
Space Complexity: O(n)
Comment on lines 3 to +6

Choose a reason for hiding this comment

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

👍


'''
if num < 1:
raise ValueError
elif num == 1:
return "1"

sequence = [0,1,1]

for i in range(3, num+1):
sequence.append(sequence[sequence[i - 1]] + sequence[i - sequence[i - 1]])
return (" ".join(map(str, sequence[1:])))