Your browser is not supported. Please, update your browser or switch to a different one. Learn more about which browsers are supported.
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) {
// write your code in JavaScript (Node.js 8.9.4)
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1]
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max()
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibStep
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = fibSteps
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = fibSteps[]
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = fibSteps[i-1] + fibSteps[i-2])
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB)
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(A[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(steA[i] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(steps(A[i]) % Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(steps(A[i]) % Math.pow(2, B[i]) - 1)
}
return result;
}
ReferenceError: steps is not defined at solution (solution.js:15:16) 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps(A[i]) % Math.pow(2, B[i]) - 1)
}
return result;
}
TypeError: fibSteps is not a function at solution (solution.js:15:21) 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log()
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fibfibSteps[A[i]])
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]])
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, )
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
return result;
}
-> fib, pow, & 5 7 5 -> fib, pow, & 5 3 1 -> fib, pow, & 8 15 8 -> fib, pow, & 8 7 0 -> fib, pow, & 1 1 1
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
console.log(result)
return result;
}
-> fib, pow, & 5 7 5 -> fib, pow, & 5 3 1 -> fib, pow, & 8 15 8 -> fib, pow, & 8 7 0 -> fib, pow, & 1 1 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
conso
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
}
console.log(result)
return result;
}
[ 1, 1, 2, 3, 5, 8 ] -> fib, pow, & 5 7 5 -> fib, pow, & 5 3 1 -> fib, pow, & 8 15 8 -> fib, pow, & 8 7 0 -> fib, pow, & 1 1 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] & Math.pow(2, B[i]) - 1);
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] Math.pow(2, B[i]) - 1);
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] & Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
console.log(result)
return result;
}
[ 1, 1, 2, 3, 5, 8 ] -> fib, pow, & 5 7 5 -> fib, pow, & 5 3 1 -> fib, pow, & 8 15 8 -> fib, pow, & 8 7 0 -> fib, pow, & 1 1 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] Math.pow(2, B[i]) - 1)
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
console.log(fibSteps)
let result = [];
for (let i = 0; i < A.length; i++) {
console.log('-> fib, pow, &', fibSteps[A[i]], Math.pow(2, B[i]) - 1, fibSteps[A[i]] % Math.pow(2, B[i]))
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
console.log(result)
return result;
}
[ 1, 1, 2, 3, 5, 8 ] -> fib, pow, & 5 7 5 -> fib, pow, & 5 3 1 -> fib, pow, & 8 15 8 -> fib, pow, & 8 7 0 -> fib, pow, & 1 1 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, 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) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
return result;
}
[[100], [10]]
[[10, 100], [10, 1]]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
return result;
}
[[100], [10]]
[[10, 100], [10, 1]]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, B) {
// write your code in JavaScript (Node.js 8.9.4)
let fibSteps = [1,1];
let max = Math.max(...A);
let maxB = Math.max(...B);
for (let i = 2; i <= max; i++) {
fibSteps[i] = (fibSteps[i-1] + fibSteps[i-2]) % Math.pow(2, maxB);
}
let result = [];
for (let i = 0; i < A.length; i++) {
result.push(fibSteps[A[i]] % Math.pow(2, B[i]));
}
return result;
}
The solution obtained perfect score.