diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6620bcd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "*test.py" + ], + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, + "python.testing.pytestArgs": [ + "tests" + ] +} \ No newline at end of file diff --git a/lib/max_subarray.py b/lib/max_subarray.py index 4e892e0..124e313 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -2,11 +2,20 @@ 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: On + Space Complexity: ON """ if nums == None: return 0 if len(nums) == 0: return 0 - pass + + max_sub_array = nums[0] + max_sub = nums[0] + + for i in range(1,len(nums)): + + max_sub = max(max_sub + nums[i], nums[i]) + max_sub_array = max(max_sub_array, max_sub) + + return max_sub_array \ No newline at end of file diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..a522a91 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -1,10 +1,32 @@ - +import array # Time complexity: ? # 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 + # to store values + if num < 1: + raise ValueError ("Invalid Num") + if num == 1: + return "1" + + f = [0, 1, 1] + output = "1" + + count = 3 + # To store values of sequence in array + + while count <= num: + f.append(f[f[count - 1]]+ f[count - f [ count -1]]) + count += 1 + number = [str(item) for item in f] + + return " ".join(number[1:]) + # for i in range(3, num + 1): + # r = f[f[i-1]]+f[i-f[i-1]] + # f.append(r); + + # return r \ No newline at end of file