Tasks Details
medium
Find the maximal sum of any double slice.
Task Score
100%
Correctness
100%
Performance
100%
A non-empty array A consisting of N integers is given.
A triplet (X, Y, Z), such that 0 ≤ X < Y < Z < N, is called a double slice.
The sum of double slice (X, Y, Z) is the total of A[X + 1] + A[X + 2] + ... + A[Y − 1] + A[Y + 1] + A[Y + 2] + ... + A[Z − 1].
For example, array A such that:
A[0] = 3 A[1] = 2 A[2] = 6 A[3] = -1 A[4] = 4 A[5] = 5 A[6] = -1 A[7] = 2contains the following example double slices:
- double slice (0, 3, 6), sum is 2 + 6 + 4 + 5 = 17,
- double slice (0, 3, 7), sum is 2 + 6 + 4 + 5 − 1 = 16,
- double slice (3, 4, 5), sum is 0.
The goal is to find the maximal sum of any double slice.
Write a function:
function solution(A);
that, given a non-empty array A consisting of N integers, returns the maximal sum of any double slice.
For example, given:
A[0] = 3 A[1] = 2 A[2] = 6 A[3] = -1 A[4] = 4 A[5] = 5 A[6] = -1 A[7] = 2the function should return 17, because no double slice of array A has a sum of greater than 17.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [3..100,000];
- each element of array A is an integer within the range [−10,000..10,000].
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 59 minutes
Notes
not defined yet
Code: 13:07:52 UTC,
java,
autosave
Code: 13:20:47 UTC,
js,
autosave
Code: 13:20:57 UTC,
js,
autosave
Code: 13:21:08 UTC,
js,
autosave
Code: 13:21: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
for (let = 0; i < A.length; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:21:52 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
for (let = 1; i < A.length; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:22:07 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
//can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:22:17 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
// can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:22: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let
// can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:22:51 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
// can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:26: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
// can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:27:01 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
// an't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:27: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:27: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
l
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:27:55 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
let positiveRun
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:33: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
let positiveRun =
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:34:05 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = true;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:34: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
}
}
}
Code: 13:34:40 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:35: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:35:37 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:35: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:36:01 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (firstPos) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:36: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (firstPos) {
if (A[i] >= 0) {
firstPos = true;
}
}
}
}
Code: 13:37: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (firstPos) {
}
}
}
Code: 13:37:22 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (firstPos) {
}
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:37:38 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (firstPos) {
}
if (A[i] >= 0) {
firstPos = true;
}
}
}
Code: 13:38:00 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
}
}
}
Code: 13:38: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i])
}
}
}
Code: 13:39:55 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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] )
}
}
}
Code: 13:40: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] >= 0 )
}
}
}
Code: 13:40: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 < 4) {
return 0;
}
let maxSum = 0;
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] >= 0 && A[i-1] >= 0) {
}
}
}
}
Code: 13: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 < 4) {
return 0;
}
let maxEnd = 0;
let firstPos = false;
let positiveRun = [];
let negativeRun = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] >= 0 && A[i-1] >= 0) {
}
}
}
}
Code: 13:43:47 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] >= 0 && A[i-1] >= 0) {
}
}
}
}
Code: 13: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
if (A[i] >= 0) {
firstPos = true;
}
if (firstPos) {
if (A[i] >= 0 && A[i-1] >= 0) {
}
}
}
}
Code: 13:44: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
}
}
Code: 13:44: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
for (let = 1; i < A.length-1; i++) {
}
}
Code: 13:44: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i])
}
}
Code: 13: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i])
maxSlice =
}
}
Code: 13:45: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i])
maxSlice = Math.max()
}
}
Code: 13:45: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = []
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i])
maxSlice = Math.max(maxSlice, maxEnd);
}
}
Code: 13:46: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [;]
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(max)
}
}
Code: 13:46: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [;]
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr)
}
Code: 13:47:01 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [;]
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return
}
Code: 13:47:06 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [;]
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
solution.js:12 let maxSliceArr = [;] ^ SyntaxError: Unexpected token ; at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) 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
Code: 13:47:17 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: i is not defined at solution (solution.js:15:21) 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
Code: 13:47: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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:47:26 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxEndArr = [];
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 17
stdout:
[ 2, 8, 7, 11, 16, 15 ] [ 2, 8, 8, 11, 16, 16 ]
Code: 13:52:39 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 < 4) {
return 0;
}
let maxEnd = 0;
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:52: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 < 4) {
return 0;
}
let sumLeft = 0
let sumRight = 0
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:53:08 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSlice = 0;
let maxSliceArr = [];
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:53:37 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
// Can't use either end value
for (let i = 1; i < A.length-1; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:53:51 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
maxEnd = Math.max(0, maxEnd + A[i]);
maxSlice = Math.max(maxSlice, maxEnd);
maxEndArr.push(maxEnd);
maxSliceArr.push(maxSlice);
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:54:22 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
if (i === 0 || i === 1) {
sumLeft[i] =
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:54:52 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:55:22 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.ma
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:55: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max()
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:55: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + )
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:56: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1])
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:56:24 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:56:55 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRec])
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:57: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRe+1])
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:57:37 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+]])
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:57:48 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0])
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:59: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0)
}
}
console.log(maxEndArr);
console.log(maxSliceArr);
return 1;
}
Code: 13:59: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; )
return 1;
}
Code: 14:00: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSum)
}
return 1;
}
Code: 14:00: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight
}
}
return 1;
}
Code: 14:01: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:01:03 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Analysis
Code: 14:01: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:01:34 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Analysis
expand all
Example tests
1.
0.076 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
Code: 14:01:55 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:02: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
Analysis
expand all
Example tests
1.
0.076 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
expand all
User tests
1.
0.076 s
OK
function result: 0
function result: 0
stdout:
[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]
Code: 14:02: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:02: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:02:42 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
expand all
User tests
1.
0.072 s
OK
function result: 0
function result: 0
stdout:
[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]
1.
0.068 s
OK
function result: 0
function result: 0
1.
0.072 s
OK
function result: 10000
function result: 10000
stdout:
[ 0, 0, 0, 10000 ] [ 0, 10000, 0, 0 ]
Code: 14:03: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:03:20 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
User test case 4:
[-10, -10, 2, 4, -1, 5, 6, -10, 10, -1]
Analysis
expand all
Example tests
1.
0.076 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
expand all
User tests
1.
0.076 s
OK
function result: 0
function result: 0
stdout:
[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]
1.
0.072 s
OK
function result: 0
function result: 0
1.
0.076 s
OK
function result: 10000
function result: 10000
stdout:
[ 0, 0, 0, 10000 ] [ 0, 10000, 0, 0 ]
1.
0.076 s
OK
function result: 26
function result: 26
stdout:
[ 0, 0, 0, 2, 6, 5, 10, 16, 6, 16 ] [ 6, 16, 14, 10, 11, 6, 0, 10, 0, 0 ]
Code: 14:04: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:04: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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
User test case 4:
[-10, -10, 2, 4, -1, 5, 6, -10, 10, -1]
User test case 5:
[-10, -10, 2, 4, -1000, 5, 6, -10, 10, -1]
Analysis
expand all
Example tests
1.
0.076 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
expand all
User tests
1.
0.076 s
OK
function result: 0
function result: 0
stdout:
[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]
1.
0.072 s
OK
function result: 0
function result: 0
1.
0.076 s
OK
function result: 10000
function result: 10000
stdout:
[ 0, 0, 0, 10000 ] [ 0, 10000, 0, 0 ]
1.
0.076 s
OK
function result: 26
function result: 26
stdout:
[ 0, 0, 0, 2, 6, 5, 10, 16, 6, 16 ] [ 6, 16, 14, 10, 11, 6, 0, 10, 0, 0 ]
1.
0.076 s
OK
function result: 21
function result: 21
stdout:
[ 0, 0, 0, 2, 6, 0, 5, 11, 1, 11 ] [ 0, 6, 4, 0, 11, 6, 0, 10, 0, 0 ]
Code: 14:06:23 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
console.log(sumRight);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
User test case 4:
[-10, -10, 2, 4, -1, 5, 6, -10, 10, -1]
User test case 5:
[-10, -10, 2, 4, -1000, 5, 6, -10, 10, -1]
Analysis
expand all
Example tests
1.
0.076 s
OK
stdout:
[ 0, 0, 2, 8, 7, 11, 16, 15 ] [ 16, 14, 8, 9, 5, 0, 0, 0 ]
expand all
User tests
1.
0.076 s
OK
function result: 0
function result: 0
stdout:
[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]
1.
0.072 s
OK
function result: 0
function result: 0
1.
0.076 s
OK
function result: 10000
function result: 10000
stdout:
[ 0, 0, 0, 10000 ] [ 0, 10000, 0, 0 ]
1.
0.076 s
OK
function result: 26
function result: 26
stdout:
[ 0, 0, 0, 2, 6, 5, 10, 16, 6, 16 ] [ 6, 16, 14, 10, 11, 6, 0, 10, 0, 0 ]
1.
0.076 s
OK
function result: 21
function result: 21
stdout:
[ 0, 0, 0, 2, 6, 0, 5, 11, 1, 11 ] [ 0, 6, 4, 0, 11, 6, 0, 10, 0, 0 ]
Code: 14:06:30 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
console.log(sumLeft);
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Code: 14:06:33 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
User test case 4:
[-10, -10, 2, 4, -1, 5, 6, -10, 10, -1]
User test case 5:
[-10, -10, 2, 4, -1000, 5, 6, -10, 10, -1]
Analysis
Code: 14:06:38 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
User test case 1:
[-1, -1, -1, -1, -1, -1, -1]
User test case 2:
[1, 2, 3]
User test case 3:
[-10000, -10000, 10000, 10000]
User test case 4:
[-10, -10, 2, 4, -1, 5, 6, -10, 10, -1]
User test case 5:
[-10, -10, 2, 4, -1000, 5, 6, -10, 10, -1]
Analysis
Code: 14:06:40 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 < 4) {
return 0;
}
let sumLeft = [];
let sumRight = [];
let maxSumLeft = 0;
let maxSumRight = 0;
for (let i = 0; i < A.length; i++) {
let iRev = A.length - 1 - i;
if (i === 0 || i === 1) {
sumLeft[i] = 0;
sumRight[iRev] = 0;
} else {
sumLeft[i] = Math.max(sumLeft[i-1] + A[i-1], A[i-1], 0);
sumRight[iRev] = Math.max(sumRight[iRev+1] + A[iRev+1], A[iRev+1], 0);
}
}
for (let i = 1; i < A.length-1; i++) {
if (sumLeft[i] + sumRight[i] > maxSumLeft + maxSumRight) {
maxSumLeft = sumLeft[i];
maxSumRight = sumRight[i];
}
}
return maxSumLeft + maxSumRight;
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N)
expand all
Correctness tests
1.
0.068 s
OK
2.
0.068 s
OK
3.
0.072 s
OK
1.
0.068 s
OK
2.
0.068 s
OK
1.
0.072 s
OK
1.
0.068 s
OK
1.
0.068 s
OK
1.
0.068 s
OK
expand all
Performance tests
1.
0.072 s
OK
1.
0.072 s
OK
1.
0.072 s
OK
1.
0.120 s
OK
1.
0.128 s
OK
1.
0.128 s
OK
1.
0.112 s
OK
2.
0.128 s
OK