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:
class Solution { public int solution(int[] 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–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Java 8
Total time used 30 minutes
Effective time used 30 minutes
Notes
not defined yet
Task timeline
Code: 15:53:15 UTC,
java,
autosave
Code: 15:53:31 UTC,
java,
autosave
Code: 15:53:41 UTC,
java,
autosave
Code: 15:53:52 UTC,
java,
autosave
Code: 15:54:23 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A. )
}
}
Code: 15:54:36 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length(); )
}
}
Code: 15:55:01 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; )
}
}
Code: 15:55:32 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int su
}
}
Code: 15:55:48 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
}
}
Code: 15:56:17 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
}
}
}
Code: 15:56:37 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
}
}
}
Code: 15:56:51 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
}
}
}
Code: 15:57:44 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if
}
}
}
Code: 15:57:56 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
}
}
}
Code: 15:58:18 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sum
}
}
}
Code: 15:58:35 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int sumAll = 0;
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:00:34 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
for( int i=0; i < A.length; sumAll+=A[i++] ) ;
int sumPrev = 0;
int sumNext = sumAll;
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:00:44 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:00:54 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:01:07 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
minValue
for(int i = 0; i < A.length; i++) {
sumNext -= A[i];
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:01:23 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( sumPrev == sumNext )
return i;
sumPrev += A[i];
}
}
}
Code: 16:01:33 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( A[i] minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:01:56 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:04:43 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:04:54 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:05:34 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int pla
minPositiveValue = 1;
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:06:05 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght);
for(int i = 0; i < A.length; i++) {
if( A[i] )
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:06:25 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght);
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < )
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:06:35 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght);
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:07:05 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:07:16 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:07:36 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[]
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:07:49 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]] =
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:07:59 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]] = A[i];
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:08:12 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
if( A[i] > 0 && A[i] < minPositiveValue )
return i;
sumPrev += A[i];
}
}
}
Code: 16:08:43 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
}
}
Code: 16:09:29 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
}
}
Code: 16:09:42 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
}
}
Code: 16:09:52 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
}
}
Code: 16:10:02 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
places[A[i]-1] = A[i];
}
}
}
Code: 16:10:16 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i-1;
}
}
}
Code: 16:10:26 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
}
}
Code: 16:10:48 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return
}
}
Code: 16:10:58 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:11:00 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Compile error
Solution.java:10: error: <identifier> expected int places[] = new(A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 .... ^ 1 error
Code: 16:11:45 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new (A.lenght); // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:11:54 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Compile error
Solution.java:10: error: cannot find symbol int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 .... ^ symbol: variable lenght location: variable A of type int[] 1 error
Code: 16:12:12 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght()]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length() )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length(); i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Compile error
Solution.java:10: error: cannot find symbol int places[] = new int[A.lenght()]; // [0]=1, [1]=2, [2]=3, [3]=4 .... ^ symbol: method lenght() location: variable A of type int[] Solution.java:12: error: cannot find symbol if( A[i] > 0 && A[i] < A.length() ) ^ symbol: method length() location: variable A of type int[] Solution.java:15: error: cannot find symbol for(int i = 0; i < places.length(); i++) { ^ symbol: method length() location: variable places of type int[] 3 errors
Code: 16:12:47 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length() )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length(); i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:12:58 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length() )
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length(); i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:13:20 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:13:27 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.lenght; i++) {
if( A[i] > 0 && A[i] < A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.lenght; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Compile error
Solution.java:10: error: cannot find symbol int places[] = new int[A.lenght]; // [0]=1, [1]=2, [2]=3, [3]=4 .... ^ symbol: variable lenght location: variable A of type int[] Solution.java:11: error: cannot find symbol for(int i = 0; i < A.lenght; i++) { ^ symbol: variable lenght location: variable A of type int[] Solution.java:15: error: cannot find symbol for(int i = 0; i < places.lenght; i++) { ^ symbol: variable lenght location: variable places of type int[] 3 errors
Code: 16:14:11 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.lengt]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.lenght; i++) {
if( A[i] > 0 && A[i] < A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.lenght; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:14:25 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] < A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Code: 16:15:16 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] <= A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:15:35 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] <= A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Analysis
Code: 16:16:10 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
if( A[i] > 0 && A[i] <= A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:16:27 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( A[i] > 0 && A[i] <= A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:16:37 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length)
places[A[i]-1] = A[i];
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:16:47 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length)
places[currVal-1] = currVal;
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:18:20 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length)
places[currVal-1] = currVal;
}
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:18:42 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length)
places[currVal-1] = currVal;
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return 1;
}
}
Code: 16:18:52 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length)
places[currVal-1] = currVal;
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return smallestPositive+1;
}
}
Code: 16:19:42 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return smallestPositive+1;
}
}
Code: 16:19:56 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
}
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return smallestPositive+1;
}
}
Code: 16:20:08 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositiove = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
}
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return smallestPositive+1;
}
}
Code: 16:20:21 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return smallestPositive+1;
}
}
Code: 16:20:36 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
if havePositive
return smallestPositive+1;
}
}
Code: 16:20:55 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
int smallestPositive = 0;
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
if( havePositive )
return smallestPositive+1;
}
}
Code: 16:21:16 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
int smallestPositive = 0;
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
} else {
}
return smallestPositive+1;
}
}
Code: 16:21:34 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
int smallestPositive = 0;
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return
} else {
}
return smallestPositive+1;
}
}
Code: 16:21:47 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length
} else {
}
return smallestPositive+1;
}
}
Code: 16:22:03 UTC,
java,
verify,
result: Failed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length;
} else {
return 1;
}
}
}
Analysis
Code: 16:22:22 UTC,
java,
autosave
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length+;
} else {
return 1;
}
}
}
Code: 16:22:24 UTC,
java,
verify,
result: Passed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length+1;
} else {
return 1;
}
}
}
Analysis
Code: 16:22:39 UTC,
java,
verify,
result: Passed
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length+1;
} else {
return 1;
}
}
}
Analysis
Code: 16:22:43 UTC,
java,
final,
score: 
100
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int places[] = new int[A.length]; // [0]=1, [1]=2, [2]=3, [3]=4 ....
boolean havePositive = false;
for(int i = 0; i < A.length; i++) {
int currVal = A[i];
if( currVal > 0 && currVal <= A.length) {
places[currVal-1] = currVal;
havePositive = true;
}
}
if( havePositive ) {
for(int i = 0; i < places.length; i++) {
if( places[i] == 0 )
return i+1;
}
return places.length+1;
} else {
return 1;
}
}
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N) or O(N * log(N))
expand all
Correctness tests
1.
0.004 s
OK
2.
0.008 s
OK
3.
0.008 s
OK
4.
0.004 s
OK
1.
0.008 s
OK
2.
0.004 s
OK
3.
0.004 s
OK
1.
0.008 s
OK
2.
0.004 s
OK
1.
0.008 s
OK
2.
0.004 s
OK
1.
0.008 s
OK
expand all
Performance tests
1.
0.028 s
OK
2.
0.020 s
OK
3.
0.032 s
OK
1.
0.220 s
OK
1.
0.248 s
OK
2.
0.244 s
OK
1.
0.172 s
OK