Tasks Details
medium
Find the smallest positive integer that does not occur in a given sequence.
Task Score
100%
Correctness
100%
Performance
100%
This is a demo task.
Write a function:
function solution(A);
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000..1,000,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 40 minutes
Notes
not defined yet
Task timeline
Code: 01:38:53 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 6.4.0)
let tmp_arr = {};
let rt_val = 1;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_arr[i] = 0;
}
}
console.log(tmp_arr);
return rt_val;
}
Analysis
expand all
Example tests
1.
0.092 s
WRONG ANSWER,
got 1 expected 5
stdout:
{ '0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0 }
1.
0.088 s
WRONG ANSWER,
got 1 expected 4
stdout:
{ '0': 0, '1': 0, '2': 0 }
1.
0.136 s
OK
stdout:
{}
Code: 01:39:07 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 6.4.0)
let tmp_arr = {};
let rt_val = 1;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_arr[A[i]] = 0;
}
}
console.log(tmp_arr);
return rt_val;
}
Analysis
expand all
Example tests
1.
0.084 s
WRONG ANSWER,
got 1 expected 5
stdout:
{ '1': 0, '2': 0, '3': 0, '4': 0, '6': 0 }
1.
0.084 s
WRONG ANSWER,
got 1 expected 4
stdout:
{ '1': 0, '2': 0, '3': 0 }
1.
0.084 s
OK
stdout:
{}
Code: 01:40:29 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 6.4.0)
let tmp_arr = {};
let rt_val = 1;
let tot=0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_arr[A[i]] = 0;
}
}
console.log(tmp_arr);
tot = tmp_arr[0]+tmp_arr[tmp_arr.length-1]/2;
console.log(tot);
return rt_val;
}
Analysis
expand all
Example tests
1.
0.084 s
WRONG ANSWER,
got 1 expected 5
stdout:
{ '1': 0, '2': 0, '3': 0, '4': 0, '6': 0 } NaN
1.
0.084 s
WRONG ANSWER,
got 1 expected 4
stdout:
{ '1': 0, '2': 0, '3': 0 } NaN
1.
0.080 s
OK
stdout:
{} NaN
Code: 01:42:24 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 6.4.0)
let tmp_arr = {};
let rt_val = 1;
let tot=0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_arr[A[i]] = 0;
}
}
console.log(tmp_arr);
tot = tmp_arr[0]+tmp_arr[tmp_arr.length-1]/2;
console.log(tmp_arr[Object.keys(tmp_arr)[0]]);
console.log(tot);
return rt_val;
}
Analysis
expand all
Example tests
1.
0.096 s
WRONG ANSWER,
got 1 expected 5
stdout:
{ '1': 0, '2': 0, '3': 0, '4': 0, '6': 0 } 0 NaN
1.
0.100 s
WRONG ANSWER,
got 1 expected 4
stdout:
{ '1': 0, '2': 0, '3': 0 } 0 NaN
1.
0.136 s
OK
stdout:
{} undefined NaN
Code: 01:42:49 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 6.4.0)
let tmp_arr = {};
let rt_val = 1;
let tot=0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_arr[A[i]] = 0;
}
}
console.log(tmp_arr);
tot = tmp_arr[0]+tmp_arr[tmp_arr.length-1]/2;
console.log(Object.keys(tmp_arr)[0]);
console.log(tot);
return rt_val;
}
Analysis
expand all
Example tests
1.
0.084 s
WRONG ANSWER,
got 1 expected 5
stdout:
{ '1': 0, '2': 0, '3': 0, '4': 0, '6': 0 } 1 NaN
1.
0.084 s
WRONG ANSWER,
got 1 expected 4
stdout:
{ '1': 0, '2': 0, '3': 0 } 1 NaN
1.
0.084 s
OK
stdout:
{} undefined NaN
Code: 01:54: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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i to tmp_arr) {
tot += tmp_arr[i];
ele_tot
}
}
return rt_val;
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:19 for(i to tmp_arr) { ^^ SyntaxError: Unexpected identifier at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.068 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:19 for(i to tmp_arr) { ^^ SyntaxError: Unexpected identifier at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.068 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:19 for(i to tmp_arr) { ^^ SyntaxError: Unexpected identifier at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
Code: 01:54:19 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
}
return rt_val;
Analysis
expand all
Example tests
1.
0.068 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.068 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.068 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
Code: 01:54:56 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
}
return rt_val;
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.076 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
1.
0.072 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
solution.js:25 }(); ^ SyntaxError: Unexpected token ) at Object.exports.runInNewContext (vm.js:71:16) at getSolution (/tmp/exec.js:392:29) at Promise.resolve.then (/tmp/exec.js:426:34) at process._tickCallback (internal/process/next_tick.js:103:7) at Module.runMain (module.js:592:11) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3
Code: 01:55:32 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
}
return rt_val;
}
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.068 s
OK
stdout:
[]
Code: 01:56:18 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.088 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.084 s
OK
stdout:
[]
Code: 01:57:57 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=0;i<tmp_arr.length;i++) {
if(tmp_arr[i] != i){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 0 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
WRONG ANSWER,
got 0 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
Code: 01:58:12 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
if(tmp_arr[i] != i){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.068 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.068 s
OK
stdout:
[]
Code: 01:58:27 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
if(tmp_arr[i-1] != i){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.068 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.068 s
OK
stdout:
[]
Code: 01:58:36 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=0;i<tmp_arr.length;i++) {
if(tmp_arr[i] != i+1){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 4 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.080 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
Code: 01:59:56 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.088 s
OK
stdout:
[]
Code: 02:00:23 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
console.log(tmp_arr[i-1]);
console.log(i);
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ] 1 1 2 2 3 3 4 4
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ] 1 1 2 2
1.
0.072 s
OK
stdout:
[]
expand all
User tests
1.
0.076 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ] 1 1 4 2
Code: 02:01:11 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
console.log(tmp_arr[i-1]);
console.log(i.toString);
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ] 1 [Function: toString] 2 [Function: toString] 3 [Function: toString] 4 [Function: toString]
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ] 1 [Function: toString] 2 [Function: toString]
1.
0.072 s
OK
stdout:
[]
expand all
User tests
1.
0.072 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ] 1 [Function: toString] 4 [Function: toString]
Code: 02:01:22 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
console.log(tmp_arr[i-1]);
console.log(i.toString());
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ] 1 1 2 2 3 3 4 4
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ] 1 1 2 2
1.
0.068 s
OK
stdout:
[]
expand all
User tests
1.
0.072 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ] 1 1 4 2
Code: 02:01:37 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
console.log(typeof tmp_arr[i-1]);
console.log(i.toString());
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ] string 1 string 2 string 3 string 4
1.
0.076 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ] string 1 string 2
1.
0.072 s
OK
stdout:
[]
expand all
User tests
1.
0.072 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ] string 1 string 2
Code: 02:01:46 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
console.log(typeof tmp_arr[i-1]);
console.log(typeof i.toString());
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ] string string string string string string string string
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ] string string string string
1.
0.072 s
OK
stdout:
[]
expand all
User tests
1.
0.072 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ] string string string string
Code: 02:03:14 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr.length;i++) {
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.112 s
WRONG ANSWER,
got 1 expected 5
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.112 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.068 s
OK
stdout:
[]
Code: 02:04:43 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr[tmp_arr.length-1];i++) {
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.120 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.116 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.108 s
OK
stdout:
[]
Code: 02:06:07 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
WRONG ANSWER,
got 3 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
Code: 02:08:22 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr[tmp_arr.length-1];i++) {
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
if(rt_val == tmp_arr[tmp_arr.length-1]) {
rt_val++;
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
WRONG ANSWER,
got 1 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
Code: 02:09:01 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.076 s
WRONG ANSWER,
got 3 expected 4
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
Code: 02:09:16 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.068 s
OK
stdout:
[ '1', '2', '3' ]
1.
0.068 s
OK
stdout:
[]
Code: 02:09:32 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
User test case 2:
[2, 3, 4, 5, 6, 7]
Analysis
expand all
Example tests
1.
0.116 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.112 s
OK
stdout:
[ '1', '2', '3' ]
1.
0.116 s
OK
stdout:
[]
expand all
User tests
1.
0.120 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ]
1.
0.116 s
OK
function result: 1
function result: 1
stdout:
[ '2', '3', '4', '5', '6', '7' ]
Code: 02:09:56 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
User test case 2:
[2, 3, 4, 5, 6, 7]
User test case 3:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15, 16]
Analysis
expand all
Example tests
1.
0.116 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.120 s
OK
stdout:
[ '1', '2', '3' ]
1.
0.116 s
OK
stdout:
[]
expand all
User tests
1.
0.112 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ]
1.
0.116 s
OK
function result: 1
function result: 1
stdout:
[ '2', '3', '4', '5', '6', '7' ]
1.
0.116 s
OK
function result: 11
function result: 11
stdout:
[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '13', '15', '16' ]
Code: 02:10:13 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
console.log(tmp_arr);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
User test case 2:
[2, 3, 4, 5, 6, 7]
User test case 3:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15, 16]
Analysis
expand all
Example tests
1.
0.072 s
OK
stdout:
[ '1', '2', '3', '4', '6' ]
1.
0.072 s
OK
stdout:
[ '1', '2', '3' ]
1.
0.072 s
OK
stdout:
[]
expand all
User tests
1.
0.072 s
OK
function result: 2
function result: 2
stdout:
[ '1', '4', '5' ]
1.
0.072 s
OK
function result: 1
function result: 1
stdout:
[ '2', '3', '4', '5', '6', '7' ]
1.
0.072 s
OK
function result: 11
function result: 11
stdout:
[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '13', '15', '16' ]
Code: 02:10:31 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
User test case 2:
[2, 3, 4, 5, 6, 7]
User test case 3:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15, 16]
Analysis
expand all
User tests
1.
0.068 s
OK
function result: 2
function result: 2
1.
0.068 s
OK
function result: 1
function result: 1
1.
0.068 s
OK
function result: 11
function result: 11
Code: 02:10:41 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
User test case 1:
[1, 4, 5]
User test case 2:
[2, 3, 4, 5, 6, 7]
User test case 3:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15, 16]
Analysis
expand all
User tests
1.
0.068 s
OK
function result: 2
function result: 2
1.
0.068 s
OK
function result: 1
function result: 1
1.
0.068 s
OK
function result: 11
function result: 11
Code: 02:10:43 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 6.4.0)
let tmp_obj = {};
let tmp_arr = new Array();
let rt_val = 1;
let all_tot = 0;
let ele_tot = 0;
for(let i=0;i<A.length;i++) {
if(A[i] > 0) {
tmp_obj[A[i]] = 0;
}
}
tmp_arr = Object.keys(tmp_obj);
if(Object.keys(tmp_arr).length > 1 || tmp_arr[Object.keys(tmp_arr)[0]] == 1) {
for(i=1;i<=tmp_arr[tmp_arr.length-1];i++) {
rt_val = i+1;
if(tmp_arr[i-1] != i.toString()){
rt_val=i;
break;
}
}
}
return rt_val;
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N) or O(N * log(N))
expand all
Correctness tests
1.
0.068 s
OK
2.
0.068 s
OK
3.
0.068 s
OK
4.
0.068 s
OK
1.
0.068 s
OK
2.
0.068 s
OK
3.
0.068 s
OK
1.
0.068 s
OK
2.
0.080 s
OK
1.
0.072 s
OK
2.
0.068 s
OK
1.
0.068 s
OK
expand all
Performance tests
1.
0.080 s
OK
2.
0.080 s
OK
3.
0.084 s
OK
1.
0.252 s
OK
1.
0.364 s
OK
2.
0.268 s
OK
1.
0.176 s
OK