From 1993daf1ae1e8318e7a8e5572455f34a1ff82e52 Mon Sep 17 00:00:00 2001 From: HaileyMatz Date: Thu, 12 Jan 2023 14:39:24 -0800 Subject: [PATCH] All tests passed --- lib/newman_conway.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 7f5341a..5530c83 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -1,6 +1,18 @@ def newman_conway(num): """ Returns a list of the Newman Conway numbers for the given value. - Time Complexity: ? - Space Complexity: ? + Time Complexity: On + Space Complexity: On """ - pass + arr = [0, 1, 1] + if num < 1: + raise ValueError + if num == 1: + return '1' + + for i in range(3, num + 1): + num = arr[arr[i-1]]+arr[i-arr[i-1]] + arr.append(num) + arr.pop(0) + + result = [str(i) for i in arr] + return " ".join(result) \ No newline at end of file