Tasks Details
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
The submission is being evaluated.
easy
1.
AbsDistinct
Compute number of distinct absolute values of sorted array elements.
Task Score
100%
Correctness
100%
Performance
100%
A non-empty array A consisting of N numbers is given. The array is sorted in non-decreasing order. The absolute distinct count of this array is the number of distinct absolute values among the elements of the array.
For example, consider array A such that:
A[0] = -5 A[1] = -3 A[2] = -1 A[3] = 0 A[4] = 3 A[5] = 6The absolute distinct count of this array is 5, because there are 5 distinct absolute values among the elements of this array, namely 0, 1, 3, 5 and 6.
Write a function:
function solution(A);
that, given a non-empty array A consisting of N numbers, returns absolute distinct count of array A.
For example, given array A such that:
A[0] = -5 A[1] = -3 A[2] = -1 A[3] = 0 A[4] = 3 A[5] = 6the function should return 5, 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 [−2,147,483,648..2,147,483,647];
- array A is sorted in non-decreasing order.
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 37 minutes
Notes
not defined yet
Code: 08:35:09 UTC,
java,
autosave
Code: 08:42:47 UTC,
js,
autosave
Code: 08:43:09 UTC,
js,
autosave
Code: 08:43:26 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
}
}
}
Code: 08:43:56 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i]
}
}
}
Code: 08:44:06 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
}
Code: 08:44:43 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let
}
Code: 08:44:53 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let
}
Code: 08:45:14 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let
}
Code: 08:45:31 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
}
Code: 08:46:02 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
while (left >= 0 && right <= A.length)
}
Code: 08:46:32 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && last)
}
}
Code: 08:46:57 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 0;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
}
}
}
Code: 08:47:27 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 & A[left])
}
}
Code: 08:47:41 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
}
}
}
Code: 08:48:11 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
l
}
}
}
Code: 08:48:42 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length)
}
}
Code: 08:49:02 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left])
}
}
Code: 08:49:12 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
}
}
}
Code: 08:50:18 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[left];
left--;
nextVal = A[left];
}
}
}
Code: 08:50:35 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
}
Code: 08:50:49 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
}
}
}
Code: 08:51:15 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
}
}
}
Code: 08:51:25 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
}
Code: 08:52:35 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
ret
}
Code: 08:52:45 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
Code: 08:53:13 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, count')
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
Code: 08:53:26 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count')
if (A[left] !== A[right] && lastVal !== newVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
Code: 08:53:36 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:')
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
Code: 08:53:42 UTC,
js,
verify,
result: Failed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
The submission is being evaluated.
Code: 08:58:34 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
}
}
return total;
}
Code: 08:58:44 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return total;
}
Code: 08:58:54 UTC,
js,
verify,
result: Failed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return total;
}
The submission is being evaluated.
Code: 08:59:06 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 08:59:19 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 08:59:33 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:00:03 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:00:16 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:00:26 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 09:00:43 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:00:54 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 09:01:05 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 09:01:14 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:01:25 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
console.log('-> left, right, lastVal, nextVal, count:', left, right, lastVal, nextVal, count)
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:01:35 UTC,
js,
autosave
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
Code: 09:02:22 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 09:11:18 UTC,
js,
verify,
result: Passed
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.
Code: 09:11:20 UTC,
js,
final,
score: 
100
// 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)
if (A.length === 1){
return 1;
}
let left = 0;
let right = 0;
for (let i = 0; i < A.length; i++) {
if (A[i] >= 0) {
left = i;
right = i;
break;
} else {
A[i] *= -1;
}
}
let lastVal = A[left];
let nextVal = lastVal;
let count = 1;
while (left >= 0 && right < A.length) {
if (A[left] !== A[right] && lastVal !== nextVal) {
count++;
}
if (left > 0 && A[left] < A[right]) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1 && A[right] < A[left]) {
lastVal = A[right];
right++;
nextVal = A[right];
} else if (left > 0) {
lastVal = A[left];
left--;
nextVal = A[left];
} else if (right < A.length - 1) {
lastVal = A[right];
right++;
nextVal = A[right];
} else {
break;
}
}
return count;
}
The submission is being evaluated.