We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6f29516 commit 8ee8642Copy full SHA for 8ee8642
1646-get-maximum-in-generated-array.js
@@ -0,0 +1,17 @@
1
+const arr = [0, 1, 1]
2
+/**
3
+ * @param {number} n
4
+ * @return {number}
5
+ */
6
+const getMaximumGenerated = function(n) {
7
+ if(arr[n] != null) return Math.max(...arr.slice(0, n + 1))
8
+ const oddOrEven = num => num % 2 === 0 ? 'even' : 'odd'
9
+ const hi = arr.length - 1
10
+ for(let i = hi + 1; i <= n; i++) {
11
+ let tmp, chk = oddOrEven(i)
12
+ if(chk === 'odd') tmp = arr[Math.floor(i / 2)] + arr[Math.floor(i / 2) + 1]
13
+ else tmp = arr[Math.floor(i / 2)]
14
+ arr[i] = tmp
15
+ }
16
+ return Math.max(...arr.slice(0, n + 1))
17
+};
0 commit comments