diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9b38853 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "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..2a26792 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -2,11 +2,18 @@ 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 nums == None or len(nums) == 0: return 0 - if len(nums) == 0: - return 0 - pass + + current_sub = 0 + max_sub = nums[0] + + for num in nums: + if current_sub < 0: + current_sub = 0 + current_sub += num + max_sub = max(max_sub, current_sub) + return max_sub diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..ed9acb5 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -4,7 +4,20 @@ # 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 < 1: + raise ValueError("invalid num") + + if num == 1: + return "1" + + list = [0,1,1] + count = 3 + while num >= count: + list.append(list[list[count-1]]+list[count - list[count-1]]) + count += 1 + + answer = [str(item) for item in list] + return " ".join(answer[1:])