We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 88fcabb commit 1da178bCopy full SHA for 1da178b
lib/newman_conway.rb
@@ -1,7 +1,15 @@
1
-
2
3
-# Time complexity: ?
4
-# Space Complexity: ?
+# Time complexity: O(n)
+# Space Complexity: O(n)
5
def newman_conway(num)
6
- raise NotImplementedError, "newman_conway isn't implemented"
+ raise ArgumentError.new("Input must be an integer greater than zero") if num < 1
+ return "1" if num == 1
+ nums = {}
7
+ nums[1] = 1
8
+ nums[2] = 1
9
+ n = 3
10
+ while n <= num
11
+ nums[n] = nums[nums[n - 1]] + nums[n - nums[n - 1]]
12
+ n += 1
13
+ end
14
+ return nums.values.join(" ")
15
end
0 commit comments