diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e99ede --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/lib/max_subarray.py b/lib/max_subarray.py index 4e892e0..e5972b3 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -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) """ 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 + + diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..210a6a3 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -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) """ - 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:])