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..b18e968 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -1,12 +1,14 @@ - 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: ? - """ + if nums == None: return 0 if len(nums) == 0: return 0 - pass + + max_array = nums[0] + current_max = nums[0] + + for i in range(1, len(nums)): + current_max = max(nums[i], current_max + nums[i]) + max_array = max(current_max, max_array) + return max_array diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..98a9e20 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -1,10 +1,24 @@ - - # 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 + if num == 0: + raise ValueError + if num == 1: + return "1" + + memo = [None] * (num + 1) + + memo[0] = 0 + memo[1] = 1 + memo[2] = 1 + + i = 3 + while i <= num: + memo[i] = memo[memo[i - 1]] + memo[i - memo[i - 1]] + i += 1 + + result = "" + str(memo[1]) + for i in range(2, len(memo)): + result += " " + str(memo[i]) + + return result