You are given N counters, initially set to 0, and you have two possible operations on them:
- increase(X) − counter X is increased by 1,
- max counter − all counters are set to the maximum value of any counter.
A non-empty array A of M integers is given. This array represents consecutive operations:
- if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
- if A[K] = N + 1 then operation K is max counter.
For example, given integer N = 5 and array A such that:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the values of the counters after each consecutive operation will be:
(0, 0, 1, 0, 0) (0, 0, 1, 1, 0) (0, 0, 1, 2, 0) (2, 2, 2, 2, 2) (3, 2, 2, 2, 2) (3, 2, 2, 3, 2) (3, 2, 2, 4, 2)The goal is to calculate the value of every counter after all operations.
Write a function:
function solution(N, A);
that, given an integer N and a non-empty array A consisting of M integers, returns a sequence of integers representing the values of the counters.
Result array should be returned as an array of integers.
For example, given:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the function should return [3, 2, 2, 4, 2], as explained above.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..N + 1].
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let trackMax = 0;
let toAdd
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
arr[A[i] - 1] += 1;
trackMax = Math.max(arr[A[i] - 1], trackMax);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let latestMax = 0;
let toAdd
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
arr[A[i] - 1] += 1;
trackMax = Math.max(arr[A[i] - 1], trackMax);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
let toAdd
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
arr[A[i] - 1] += 1;
trackMax = Math.max(arr[A[i] - 1], trackMax);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
let toAdd
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
arr[A[i] - 1] += 1;
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
let toAdd
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
if
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
arr[A[i] - 1] += 1;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
if(furthest)
arr[A[i] - 1] += 1;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
if(A[i] - 1 > furthest) {
arr[A[i] - 1] += 1;
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 > furthest) {
arr[A[i] - 1] += 1;
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else {
arr[]
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If we
arr[A[i] - 1] = furthest
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i )
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < A.length; ++i) {
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < A.length; ++i) {
furthest = Math.max(arr[A[i] - 1], furthest);
furthest = Math.max(arr[A[i] - 1], furthest);
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < A.length; ++i) {
if(A[i] < N) {
A[i] = N;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < A.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number found
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < ar.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number found
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
c
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 0, 0, 0, 0, NaN ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructi
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1] += 1;
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(A[i] - 1 >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 0, 0, 0, 0, NaN ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] - 1 >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] - 1 >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
[ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] - 1 >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
0 [ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] - 1 >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
1 [ 0, 0, 0, 0, 0, 2 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[i] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
1 [ 0, 0, 0, 0, 0, 2 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[Ai] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[A[i]] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
1 [ 0, 0, 0, 0, 0, 2 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
1 [ 0, 0, 0, 0, 0, 2 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
consol
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] + 1, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
1 1 [ 0, 0, 0, 0, 0, 2 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1] +, furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
0 0 [ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(arr[A[i] - 1] >= furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(arr[A[i] - 1] >= furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
false 0 [ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
undefined 0 0 [ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 < N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
6 undefined 0 0 [ 0, 0, 0, 0, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] - 1 > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
3 0 0 4 0 0 4 1 0 6 undefined 0 1 0 0 4 2 0 4 3 0 0 [ 1, 0, 1, 4, 0, 1 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] >= N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 4 0 0 4 1 0 1 0 NaN 4 2 NaN 4 NaN NaN NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 4 0 0 4 1 0 1 0 NaN 4 2 NaN 4 NaN NaN NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 4 0 0 4 1 0 1 0 NaN 4 2 NaN 4 NaN NaN NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 [ 0, 0, 1, 0, 0 ] 4 0 0 [ 0, 0, 1, 1, 0 ] 4 1 0 [ 0, 0, 1, 2, 0 ] 1 0 NaN [ NaN, 0, 1, 2, 0 ] 4 2 NaN [ NaN, 0, 1, NaN, 0 ] 4 NaN NaN [ NaN, 0, 1, NaN, 0 ] NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
c
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
console.log(furthest)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 [ 0, 0, 1, 0, 0 ] 4 0 0 [ 0, 0, 1, 1, 0 ] 4 1 0 [ 0, 0, 1, 2, 0 ] NaN 1 0 NaN [ NaN, 0, 1, 2, 0 ] 4 2 NaN [ NaN, 0, 1, NaN, 0 ] 4 NaN NaN [ NaN, 0, 1, NaN, 0 ] NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
console.log("fur:",arr[A[i] - 1], furthest)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
Invalid result type, integer expected, non-integer number foundstdout:
3 0 0 [ 0, 0, 1, 0, 0 ] 4 0 0 [ 0, 0, 1, 1, 0 ] 4 1 0 [ 0, 0, 1, 2, 0 ] fur: undefined NaN 1 0 NaN [ NaN, 0, 1, 2, 0 ] 4 2 NaN [ NaN, 0, 1, NaN, 0 ] 4 NaN NaN [ NaN, 0, 1, NaN, 0 ] NaN [ NaN, 0, 1, NaN, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
lt
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
console.log("fur:",arr[A[i] - 1], furthest)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
console.log("fur:",arr[A[i] - 1], furthest)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
legitLeadingValue = Math.max(legitLeadingValue,)
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let furthest = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
furthest = Math.max(arr[A[i] - 1], furthest);
console.log("fur:",arr[A[i] - 1], furthest)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], furthest)
if(arr[A[i] - 1] >= furthest) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = furthest + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
console.log(arr)
}
}
console.log(furthest, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < furthest) {
arr[i] = furthest;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(arr[A[i] - 1], startingLine);
console.log("fur:",arr[A[i] - 1], startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
console.log(arr)
}
}
console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(legitLeadingValue, startingLine);
console.log("fur:",arr[A[i] - 1], startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
console.log(arr)
}
}
console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(legitLeadingValue, startingLine);
console.log("fur:", legitLeadingValue, startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
console.log(arr)
}
}
console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
3 0 0 [ 0, 0, 1, 0, 0 ] 4 0 0 [ 0, 0, 1, 1, 0 ] 4 1 0 [ 0, 0, 1, 2, 0 ] fur: 2 2 1 0 2 [ 3, 0, 1, 2, 0 ] 4 2 2 [ 3, 0, 1, 3, 0 ] 4 3 2 [ 3, 0, 1, 4, 0 ] 2 [ 3, 0, 1, 4, 0 ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(legitLeadingValue, startingLine);
console.log("fur:", legitLeadingValue, startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
// console.log(arr)
}
}
console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(legitLeadingValue, startingLine);
// console.log("fur:", legitLeadingValue, startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
// console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
// console.log(arr)
}
}
// console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N, A) {
// write your code in JavaScript (Node.js 8.9.4)
let arr = new Array(N).fill(0);
let startingLine = 0;
let legitLeadingValue = 0;
// Loop through all instructions.
for (let i = 0; i < A.length; ++i) {
// if 6 > 5
if(A[i] > N) {
startingLine = Math.max(legitLeadingValue, startingLine);
// console.log("fur:", legitLeadingValue, startingLine)
} else {
// arr.fill(trackMax);
// We update for those that is at/after `furthest`
// console.log(A[i], arr[A[i] - 1], startingLine)
if(arr[A[i] - 1] >= startingLine) {
++arr[A[i] - 1];
} else { // If this has fallen behind, then we need to catch up.
arr[A[i] - 1] = startingLine + 1;
}
legitLeadingValue = Math.max(legitLeadingValue, arr[A[i] - 1]);
// console.log(arr)
}
}
// console.log(startingLine, arr)
// Make sure to catch up those that has not has a chance to increment after that last `furthest`.
for(let i = 0; i < arr.length; ++i) {
if(arr[i] < startingLine) {
arr[i] = startingLine;
}
}
return arr;
}
The solution obtained perfect score.