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
24 changes: 18 additions & 6 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)
"""
if nums == None:
if not nums:
return 0
if len(nums) == 0:
return 0
pass
if max(nums) < 0:
return max(nums)

#Implementation of Kadane's Algorithm

maxSum = 0
currSum = 0

for i in range(len(nums)):
currSum = currSum + nums[i]
if(currSum > maxSum):
maxSum = currSum
if(currSum < 0):
currSum = 0
Comment on lines +19 to +23

Choose a reason for hiding this comment

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

Just a little simpler.

Suggested change
currSum = currSum + nums[i]
if(currSum > maxSum):
maxSum = currSum
if(currSum < 0):
currSum = 0
currSum = max(currSum + nums[i], nums[i])
maxSum = max(currSum, maxSum)

return maxSum
24 changes: 19 additions & 5 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@


# 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 9

Choose a reason for hiding this comment

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

👍 Nice

pass
if num == 0:
raise ValueError("Integer cannot be zero")

if num == 1:
return "1"

if num == 2:
return "1 1"

nums = [0, 1, 1]

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

return " ".join([str(item) for item in nums[1:num+1]])