Tasks Details
easy
1.
Triangle
Determine whether a triangle can be built from a given set of edges.
Task Score
93%
Correctness
90%
Performance
100%
An array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P < Q < R < N and:
- A[P] + A[Q] > A[R],
- A[Q] + A[R] > A[P],
- A[R] + A[P] > A[Q].
For example, consider array A such that:
A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A[5] = 20Triplet (0, 2, 4) is triangular.
Write a function:
function solution(A);
that, given an array A consisting of N integers, returns 1 if there exists a triangular triplet for this array and returns 0 otherwise.
For example, given array A such that:
A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A[5] = 20the function should return 1, as explained above. Given array A such that:
A[0] = 10 A[1] = 50 A[2] = 5 A[3] = 1the function should return 0.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [0..100,000];
- each element of array A is an integer within the range [−2,147,483,648..2,147,483,647].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 11 minutes
Notes
not defined yet
Task timeline
Code: 10:57:33 UTC,
java,
autosave
Code: 10:57:53 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// 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)
// mergeSort ->
// 분할
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
console.log(divided)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
debugger;
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 10:58:00 UTC,
js,
verify,
result: Failed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// 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)
// mergeSort ->
// 분할
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
console.log(divided)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
debugger;
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Analysis
expand all
Example tests
example
example, positive answer, length=6
example, positive answer, length=6
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 2 ], [ 5 ], [ 1 ], [ 8 ], [ 20 ] ]
example1
example, answer is zero, length=4
example, answer is zero, length=4
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 50 ], [ 5 ], [ 1 ] ]
Code: 10:58:13 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
console.log(divided)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
debugger;
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 10:58:17 UTC,
js,
verify,
result: Failed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
console.log(divided)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
debugger;
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Analysis
expand all
Example tests
example
example, positive answer, length=6
example, positive answer, length=6
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 2 ], [ 5 ], [ 1 ], [ 8 ], [ 20 ] ]
example1
example, answer is zero, length=4
example, answer is zero, length=4
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 50 ], [ 5 ], [ 1 ] ]
Code: 10:58:32 UTC,
js,
verify,
result: Failed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
console.log(divided)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Analysis
expand all
Example tests
example
example, positive answer, length=6
example, positive answer, length=6
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 2 ], [ 5 ], [ 1 ], [ 8 ], [ 20 ] ]
example1
example, answer is zero, length=4
example, answer is zero, length=4
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' foundstdout:
[ [ 10 ], [ 50 ], [ 5 ], [ 1 ] ]
Code: 10:58:54 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 10:58:57 UTC,
js,
verify,
result: Failed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Analysis
expand all
Example tests
example
example, positive answer, length=6
example, positive answer, length=6
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' found
example1
example, answer is zero, length=4
example, answer is zero, length=4
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, 'object' found
Code: 10:59:06 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 10:59:16 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
debugger;
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 11:00:43 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
deb
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 11:00:53 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
return finalMerged
}
Code: 11:01:34 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
rfinalMerged
}
Code: 11:01:55 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
finalMerged
for(let i=0; i<final)
}
Code: 11:02:11 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
finalMerged
for(let i=0; i<finalMerged.length; i++){
if(A[i])
}
}
Code: 11:02:21 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
finalMerged
for(let i=0; i<finalMerged.length-2; i++){
if(A[i]+A[i+1])
}
}
Code: 11:02:43 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
for(let i=0; i<finalMerged.length-2; i++){
if(A[i]+A[i+1]>A[i+2]) return 1;
}
return 0;
}
Code: 11:02:44 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
for(let i=0; i<finalMerged.length-2; i++){
if(A[i]+A[i+1]>A[i+2]) return 1;
}
return 0;
}
Analysis
Code: 11:03:13 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Code: 11:03:14 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Analysis
Code: 11:08:13 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)[]
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Code: 11:08:17 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)[0]
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Analysis
Code: 11:08:20 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)[0]
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Analysis
Code: 11:08:22 UTC,
js,
final,
score: 
93
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
// 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)
const divided = []
const divideArr = (arr)=>{
if(arr.length===1){
divided.push(arr);
return arr;
}
const mid = parseInt(arr.length/2)
const first = arr.slice(0,mid)
const second = arr.slice(mid)
divideArr(first)
divideArr(second)
}
divideArr(A)
let merged = divided.slice(0)
const mergeAB = (a,b)=> {
if(b===undefined) return a;
let length = a.length+b.length
let mergeArr = []
let aCompare = a[0]
let bCompare = b[0]
let bIndex = 0;
let aIndex = 0;
for(let i =0; i<length; i++){
if(aCompare>bCompare){
mergeArr[i]=bCompare
bIndex +=1
if(bIndex===b.length){
return mergeArr = mergeArr.concat(a.slice(aIndex))
}
else{
bCompare=b[bIndex]
}
}
else{
mergeArr[i]=aCompare
aIndex +=1
if(aIndex===a.length){
return mergeArr = mergeArr.concat(b.slice(bIndex))
}
else{
aCompare=a[aIndex]
}
}
}
return mergeArr
}
const mergeArr = (mergedArr)=> {
if(mergedArr.length===1) return mergedArr
let newMergeArr = []
for(let i =0; i<mergedArr.length; i+=2){
newMergeArr.push(mergeAB(mergedArr[i], mergedArr[i+1]))
}
return mergeArr(newMergeArr)
}
const finalMerged = mergeArr(merged)[0]
for(let i=0; i<finalMerged.length-2; i++){
if(finalMerged[i]+finalMerged[i+1]>finalMerged[i+2]) return 1;
}
return 0;
}
Analysis summary
The following issues have been detected: runtime errors.
For example, for the input [] the solution terminated unexpectedly.
Analysis
Detected time complexity:
O(N*log(N))
expand all
Correctness tests
1.
0.088 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
RangeError: Maximum call stack size exceeded at divideArr (solution.js:9:19) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5) at divideArr (solution.js:17:5)
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.080 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.112 s
OK
1.
0.076 s
OK
2.
0.072 s
OK
3.
0.076 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.076 s
OK
5.
0.072 s
OK
6.
0.072 s
OK
expand all
Performance tests
1.
0.128 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.068 s
OK
6.
0.072 s
OK
1.
0.220 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.068 s
OK
6.
0.072 s
OK
1.
0.372 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.068 s
OK
5.
0.068 s
OK
6.
0.068 s
OK
1.
0.376 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.068 s
OK
6.
0.072 s
OK
1.
0.372 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.068 s
OK
1.
0.352 s
OK
2.
0.072 s
OK
3.
0.068 s
OK
4.
0.072 s
OK
5.
0.072 s
OK
6.
0.072 s
OK