Task description
You have to climb up a ladder. The ladder has exactly N rungs, numbered from 1 to N. With each step, you can ascend by one or two rungs. More precisely:
- with your first step you can stand on rung 1 or 2,
- if you are on rung K, you can move to rungs K + 1 or K + 2,
- finally you have to stand on rung N.
Your task is to count the number of different ways of climbing to the top of the ladder.
For example, given N = 4, you have five different ways of climbing, ascending by:
- 1, 1, 1 and 1 rung,
- 1, 1 and 2 rungs,
- 1, 2 and 1 rung,
- 2, 1 and 1 rungs, and
- 2 and 2 rungs.
Given N = 5, you have eight different ways of climbing, ascending by:
- 1, 1, 1, 1 and 1 rung,
- 1, 1, 1 and 2 rungs,
- 1, 1, 2 and 1 rung,
- 1, 2, 1 and 1 rung,
- 1, 2 and 2 rungs,
- 2, 1, 1 and 1 rungs,
- 2, 1 and 2 rungs, and
- 2, 2 and 1 rung.
The number of different ways can be very large, so it is sufficient to return the result modulo 2P, for a given integer P.
Write a function:
function solution(A, B);
that, given two non-empty arrays A and B of L integers, returns an array consisting of L integers specifying the consecutive answers; position I should contain the number of different ways of climbing the ladder with A[I] rungs modulo 2B[I].
For example, given L = 5 and:
A[0] = 4 B[0] = 3 A[1] = 4 B[1] = 2 A[2] = 5 B[2] = 4 A[3] = 5 B[3] = 3 A[4] = 1 B[4] = 1the function should return the sequence [5, 1, 8, 0, 1], as explained above.
Write an efficient algorithm for the following assumptions:
- L is an integer within the range [1..50,000];
- each element of array A is an integer within the range [1..L];
- each element of array B is an integer within the range [1..30].
Task timeline
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// calculate Fibonacci numbers until N
const N = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > N) break;
fibs.push(nextFib);
index++;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > N) break;
fibs.push(nextFib);
index++;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > N) break;
fibs.push(nextFib);
index++;
}
con
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > N) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
}
ReferenceError: N is not defined at solution (solution.js:12:23) at solutionWrapper (/tmp/exec.js:419:28) at Promise.resolve.then (/tmp/exec.js:445:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const max = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
for (let i = 0; i < L; i++) {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A) + 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A) + 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs + 1) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = Math.max(...A);
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const maxRugs = A.len;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > maxRugs) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const L = A.length;
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = fibs[index - 1] + fibs[index - 2];
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = (fibs[index - 1] + fibs[index - 2]);
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = (fibs[index - 1] + fibs[index - 2]) %;
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
let index = 2;
while (true) {
const nextFib = (fibs[index - 1] + fibs[index - 2]) % limit;
if (nextFib > L) break;
fibs.push(nextFib);
index++;
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/opt/lang/nodejs/bin/node] 2: 0x128059c [/opt/lang/nodejs/bin/node] 3: v8::Utils::ReportOOMFailure(char const*, bool) [/opt/lang/nodejs/bin/node] 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/opt/lang/nodejs/bin/node] 5: v8::internal::Factory::NewFixedDoubleArray(int, v8::internal::PretenureFlag) [/opt/lang/nodejs/bin/node] 6: 0xe0aba7 [/opt/lang/nodejs/bin/node] 7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/opt/lang/nodejs/bin/node] 8: 0x190fde58463dstdout:
<--- Last few GCs ---> [3:0x3c49a60] 1622 ms: Mark-sweep 83.7 (90.5) -> 83.7 (90.5) MB, 2.3 / 0.0 ms allocation failure GC in old space requested [3:0x3c49a60] 1626 ms: Mark-sweep 83.7 (90.5) -> 83.7 (87.5) MB, 3.9 / 0.0 ms last resort GC in old space requested [3:0x3c49a60] 1628 ms: Mark-sweep 83.7 (87.5) -> 83.7 (87.5) MB, 2.4 / 0.0 ms last resort GC in old space requested <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 0x270b0f025ee1 <JSObject> 1: solution [solution.js:~4] [pc=0x190fde7052f7](this=0x31e2f144df79 <JSGlobal Object>,A=0x31e2f144df59 <JSArray[5]>,B=0x31e2f144df39 <JSArray[5]>) 3: solutionWrapper(aka solutionWrapper) [/tmp/exec.js:419] [bytecode=0xc3d7b0f2b89 offset=22](this=0x31e2f1402311 <undefined>) 4: arguments adaptor frame: 2->0 6: /* anonymous */(aka /* anonymous */) [/tmp/exec.js:445] [bytecode=0xc3d...
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
const nextFib = (fibs[index - 1] + fibs[index - 2]) % limit;
fibs.push(nextFib);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
ReferenceError: index is not defined at solution (solution.js:10:31) at solutionWrapper (/tmp/exec.js:419:28) at Promise.resolve.then (/tmp/exec.js:445:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
const nextFib = ;
fibs.push((fibs[index - 1] + fibs[index - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, NaN, NaN, NaN ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(B)) - 1;
console.log(limit);
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
0 [ 1, 1, NaN, NaN, NaN ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(..B)) - 1;
console.log(limit);
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
console.log(limit);
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
15 [ 1, 1, 2, 3, 5 ] []
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push();
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[i]);
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]]);
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] [ 5, 5, NaN, NaN, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] 5 5 undefined undefined 1 [ 5, 5, NaN, NaN, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i] - ])
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i] - 1])
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5 ] 3 3 5 5 1 [ 5, 5, NaN, NaN, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i] - 1])
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % limit);
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1 [ 5, 5, 8, 8, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % B[i]);
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1 [ 2, 1, 0, 2, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % *());
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % (1 << B[i]) - 1);
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % ((1 << B[i]) - 1));
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1 [ 5, 2, 8, 1, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % ((1 << B[i]) 1));
}
console.log(result);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = (1 << Math.max(...B)) - 1;
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % ((1 << B[i])));
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1 [ 5, 1, 8, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % (1 << B[i]));
}
console.log(result);
}
Invalid result type, Array expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1 [ 5, 1, 8, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
console.log(fibs[A[i]])
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
[ 1, 1, 2, 3, 5, 8 ] 5 5 8 8 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
[[4, 4], []]
[[3, 2], []]
Invalid result type, integer expected, non-integer number foundstdout:
[ 1, 1, 0 ]
Invalid result type, integer expected, non-integer number foundstdout:
[ 1, 1, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
[[4, 4, 4, 4], []]
function result: [0, 0, 0, 0]
[ 1, 1, 0, 0, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
[[4, 4, 8, 9], []]
Invalid result type, integer expected, non-integer number foundstdout:
[ 1, 1, 0, 0, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
[4 4] [8 7]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
console.log(fibs);
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
const L = A.length;
const limit = 1 << Math.max(...B);
const fibs = [1, 1];
for (let i = 2; i < L + 1; i++) {
fibs.push((fibs[i - 1] + fibs[i - 2]) % limit);
}
const result = [];
for (let i = 0; i < L; i++) {
result.push(fibs[A[i]] % (1 << B[i]));
}
return result;
}
The solution obtained perfect score.