A non-empty array A consisting of N integers is given.
A peak is an array element which is larger than its neighbors. More precisely, it is an index P such that 0 < P < N − 1, A[P − 1] < A[P] and A[P] > A[P + 1].
For example, the following array A:
A[0] = 1 A[1] = 2 A[2] = 3 A[3] = 4 A[4] = 3 A[5] = 4 A[6] = 1 A[7] = 2 A[8] = 3 A[9] = 4 A[10] = 6 A[11] = 2has exactly three peaks: 3, 5, 10.
We want to divide this array into blocks containing the same number of elements. More precisely, we want to choose a number K that will yield the following blocks:
- A[0], A[1], ..., A[K − 1],
- A[K], A[K + 1], ..., A[2K − 1],
...- A[N − K], A[N − K + 1], ..., A[N − 1].
What's more, every block should contain at least one peak. Notice that extreme elements of the blocks (for example A[K − 1] or A[K]) can also be peaks, but only if they have both neighbors (including one in an adjacent blocks).
The goal is to find the maximum number of blocks into which the array A can be divided.
Array A can be divided into blocks as follows:
- one block (1, 2, 3, 4, 3, 4, 1, 2, 3, 4, 6, 2). This block contains three peaks.
- two blocks (1, 2, 3, 4, 3, 4) and (1, 2, 3, 4, 6, 2). Every block has a peak.
- three blocks (1, 2, 3, 4), (3, 4, 1, 2), (3, 4, 6, 2). Every block has a peak. Notice in particular that the first block (1, 2, 3, 4) has a peak at A[3], because A[2] < A[3] > A[4], even though A[4] is in the adjacent block.
However, array A cannot be divided into four blocks, (1, 2, 3), (4, 3, 4), (1, 2, 3) and (4, 6, 2), because the (1, 2, 3) blocks do not contain a peak. Notice in particular that the (4, 3, 4) block contains two peaks: A[3] and A[5].
The maximum number of blocks that array A can be divided into is three.
Write a function:
function solution(A);
that, given a non-empty array A consisting of N integers, returns the maximum number of blocks into which A can be divided.
If A cannot be divided into some number of blocks, the function should return 0.
For example, given:
A[0] = 1 A[1] = 2 A[2] = 3 A[3] = 4 A[4] = 3 A[5] = 4 A[6] = 1 A[7] = 2 A[8] = 3 A[9] = 4 A[10] = 6 A[11] = 2the function should return 3, as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [0..1,000,000,000].
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i * i < A.length; i++) {
if (A.length % i === 0) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i * i < A.length; i++) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
if ()
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i * i < A.length; i++) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
if (i * i === A.length) {
factors.push(i);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i * i < A.length; i++) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i * < A.length; i++) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let i;
for (let i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 1; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0 || A)
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0 || i === A.length-1) {
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0) {
} else if|| i === A.length-1) {
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0) {
} else if (i === A.length-1) {
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0) {
} else if (i === A.length-1) {
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0) {
} else if (i === A.length-1) {
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0) {
} else if (i === A.length-1) {
peak = true;
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
if (i === 0 && A[i] > A[i+]) {
peak
} else if (i === A.length-1) {
peak = true;
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+]) {
peak = true
} else if (i === A.length-1) {
peak = true;
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+]) {
peak = true
} else if (i === A.length-1 && A[i] > ) {
peak = true;
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if ()
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if ()
if (peak) {
peakIdx.push()
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1])
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[])
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = fa
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 0 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
ad
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length) {
factors.push(i);
}
peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrt) {
factors.push(i);
}
peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factor.sort((a,b) => a-b);
for
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (factor of factors)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (factor of factors) {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
fo
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peaks.length)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (i > 1 && i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length === 1) {
return 1;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} else if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
let peak = false;
if (i === 0 && A[i] > A[i+1]) {
peak = true
} else if (i === A.length-1 && A[i] > A[i-1]) {
peak = true;
} if (A[i-1] < A[i] && A[i+1] < A[i]) {
peak = true
}
if (peak) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length-1; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length - 1; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length - 1; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length - 1; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
for (let i = 0; i < A.length; i++) {
if (A.length % i === 0)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length - 1; i++) {
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
for (let i = 0; i < A.length; i++) {
if (A.length % i === 0) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 0; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = ; i < A.length; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++)
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
for (let j = 0; j < peakIdx.length; j++) {
if
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup
for (let j = 0; j < peakIdx.length; j++) {
if
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parse)
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/))
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]))
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
}
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
lastGroup++;
}
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
lastGroup++;
}
}
if
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let lastGroup = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === )
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxLimit =
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxLim
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
if (factors[factors.length-1-i] > max)
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount =
if (groupHasPeak + 1 === factors[factors.length-1-i]) {
if (factors[factors.length-1-i] > maxSize) {
}
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return 1;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
for (let i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
ReferenceError: i is not defined at solution (solution.js:28:5) at solutionWrapper (/tmp/exec.js:402:28) at Promise.resolve.then (/tmp/exec.js:428: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) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === lastGroup + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
ReferenceError: lastGroup is not defined at solution (solution.js:36:53) at solutionWrapper (/tmp/exec.js:402:28) at Promise.resolve.then (/tmp/exec.js:428: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) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
[10, 1, 1, 10]
function result: 3
function result: 0
function result: 0
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
[10, 1, 1, 10]
[1, 10, 10, 1]
function result: 3
function result: 0
function result: 0
function result: 0
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (peakIdx < 2) {
return pealIdx.length
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (peakIdx < 2) {
return pealIdx.length;
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
[10, 1, 1, 10]
[1, 10, 10, 1]
function result: 3
function result: 0
ReferenceError: pealIdx is not defined at solution (solution.js:30:9) at solutionWrapper (/tmp/exec.js:402:28) at Promise.resolve.then (/tmp/exec.js:428: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
ReferenceError: pealIdx is not defined at solution (solution.js:30:9) at solutionWrapper (/tmp/exec.js:402:28) at Promise.resolve.then (/tmp/exec.js:428: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) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (peakIdx < 2) {
return peakIdx.length;
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
[10, 1, 1, 10]
[1, 10, 10, 1]
function result: 3
function result: 0
function result: 0
function result: 0
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (peakIdx < 2) {
return peakIdx.length;
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
[1, 2, 3, 2, 1, 3, 1, 3, 2]
[1]
[10, 1, 1, 10]
[1, 10, 10, 1]
function result: 3
function result: 0
function result: 0
function result: 0
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let peakIdx = [];
let factors = [];
let maxSize = 0;
if (A.length < 3) {
return 0;
}
let overSqrtN = false
let i;
for (i = 1; i < A.length-1; i++) {
if ( i * i < A.length) {
if (A.length % i === 0) {
factors.push(i);
factors.push(A.length / i);
}
} else if (i * i === A.length && !overSqrtN) {
factors.push(i);
overSqrtN = true;
}
if (A[i-1] < A[i] && A[i+1] < A[i]) {
peakIdx.push(i);
}
}
if (peakIdx < 2) {
return peakIdx.length;
}
if (i * i === A.length) {
factors.push(i);
}
factors.sort((a,b) => a-b);
for (let i = 0; i < factors.length; i++) {
let groupHasPeak = -1;
for (let j = 0; j < peakIdx.length; j++) {
if (parseInt(peakIdx[j]/factors[i]) === groupHasPeak + 1) {
groupHasPeak++;
}
}
const blockCount = factors[factors.length-1-i]
if (groupHasPeak + 1 === blockCount) {
if (blockCount > maxSize) {
maxSize = blockCount;
}
}
}
return maxSize;
}
The following issues have been detected: timeout errors.
large test anti slow solutions
running time: 0.460 sec., time limit: 0.448 sec.