Tasks Details
medium
Compute number of inversion in an array.
Task Score
72%
Correctness
100%
Performance
40%
An array A consisting of N integers is given. An inversion is a pair of indexes (P, Q) such that P < Q and A[Q] < A[P].
Write a function:
class Solution { public int solution(int[] A); }
that computes the number of inversions in A, or returns −1 if it exceeds 1,000,000,000.
For example, in the following array:
A[0] = -1 A[1] = 6 A[2] = 3 A[3] = 4 A[4] = 7 A[5] = 4there are four inversions:
(1,2) (1,3) (1,5) (4,5)so the function should return 4.
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–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Java 21
Time spent on task 27 minutes
Notes
not defined yet
Code: 03:28:04 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(A[i]<A[j]) count++;
else i=j;
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.317 s
WRONG ANSWER,
got 9 expected 4
Code: 03:28:19 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else i=j;
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.322 s
WRONG ANSWER,
got 3 expected 4
Code: 03:29:06 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else i=j;
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
Code: 03:30:01 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else{
i=j-1;
break;
}
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.329 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at Solution.solution(Solution.java:15) at wrapper.run(wrapper.java:40) at wrapper.main(wrapper.java:29)
Code: 03:30:15 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else{
i=j-1;
break;
}
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
Code: 03:30:40 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else{
i=j-1;
}
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.339 s
RUNTIME ERROR,
tested program terminated unexpectedly
stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at Solution.solution(Solution.java:15) at wrapper.run(wrapper.java:40) at wrapper.main(wrapper.java:29)
Code: 03:30:56 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else{
i=j;
}
}
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.323 s
WRONG ANSWER,
got 3 expected 4
Code: 03:31:55 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
while(i<len){
for(int j=i;j<len;j++){
if(A[i]>A[j]) count++;
else{
i=j;
}
}
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.318 s
WRONG ANSWER,
got 3 expected 4
Code: 03:34:26 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
j++;
}
else{
i=j;
break;
}
}
//}
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.319 s
WRONG ANSWER,
got 0 expected 4
Code: 03:34:58 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
j++;
}
else{
i=j;
}
}
//}
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
Code: 03:35:42 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
j++;
}
else{
i=j;
j=len;
}
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.323 s
WRONG ANSWER,
got 0 expected 4
Code: 03:36:01 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
//j++;
}
else{
i=j;
}
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.338 s
WRONG ANSWER,
got 3 expected 4
Code: 03:36:43 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
//j++;
}
else{
i=j;
}
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.336 s
WRONG ANSWER,
got 3 expected 4
stdout:
(6,3) (6,4) (7,4)
Code: 03:37:32 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
//j++;
}
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
Code: 03:37:48 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
//j++;
}else break;
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.339 s
WRONG ANSWER,
got 0 expected 4
Code: 03:38:36 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
//j++;
}else j=len;
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
1.353 s
WRONG ANSWER,
got 0 expected 4
Code: 03:38:46 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
//for(int j=i;j<len;j++){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
//j++;
}
j++;
}
//if(j!=len)
i++;
}
return count;
}
}
Analysis
Code: 03:40:08 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
}else{ k=i; }
j++;
}
if(k!=0) i=k;
else i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
stdout:
(6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6,4) (6,3) (6,4) (6
Code: 03:42:24 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
}else{ k=j; }
j++;
}
if(k!=0) i=k;
else i++;
}
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
Code: 03:42:57 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
System.out.println("("+A[i]+","+A[j]+")");
}//else{ k=j; }
j++;
}
if(k!=0) i=k;
else i++;
}
return count;
}
}
Analysis
Code: 03:44:19 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
if(k!=0) i=k;
else i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
Code: 03:45:20 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
Code: 03:45:47 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
Code: 03:46:10 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Code: 03:46:33 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:47:09 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:48:10 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}else{k=j;}
j++;
}
if(k!=0) i=k;
else i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
expand all
Example tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
expand all
User tests
1.
5.000 s
TIMEOUT ERROR,
running time: >5.00 sec., time limit: 5.00 sec.
1.
1.246 s
OK
function result: 45
function result: 45
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:48:59 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
int k=0;
while(i<len){
k=0;
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}else{k=j;}
j++;
}
if(k!=0) i=k;
else i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
expand all
Example tests
1.
1.345 s
WRONG ANSWER,
got 0 expected 4
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:50:24 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
k=0;
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
Compile error
Solution.java:16: error: cannot find symbol k=0; ^ symbol: variable k location: class Solution 1 error
Code: 03:50:35 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:50:46 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis
User test case 1:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
User test case 2:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Code: 03:50:54 UTC,
java,
final,
score: 
72
// 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");
import java.math.BigDecimal;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len=A.length;
int count=0;
int i=0;
int j=0;
while(i<len){
j=i+1;
while(j<len){
if(A[i]>A[j]){
count++;
}
j++;
}
i++;
}
if(count>1000000000) count=-1;
return count;
}
}
Analysis summary
The following issues have been detected: timeout errors.
Analysis
Detected time complexity:
O(N**2)
expand all
Correctness tests
1.
1.330 s
OK
1.
1.336 s
OK
1.
1.335 s
OK
1.
1.345 s
OK
2.
1.329 s
OK
3.
1.325 s
OK
4.
1.335 s
OK
1.
1.332 s
OK
1.
1.324 s
OK
expand all
Performance tests
1.
1.335 s
OK
1.
2.293 s
OK
1.
5.179 s
TIMEOUT ERROR,
running time: 5.18 sec., time limit: 2.71 sec.
1.
8.000 s
TIMEOUT ERROR,
running time: >8.00 sec., time limit: 2.85 sec.
big_monotonic
long descending and non-ascending sequence
long descending and non-ascending sequence
✘
TIMEOUT ERROR
running time: >8.00 sec., time limit: 2.97 sec.
running time: >8.00 sec., time limit: 2.97 sec.
1.
8.000 s
TIMEOUT ERROR,
running time: >8.00 sec., time limit: 2.97 sec.
2.
9.000 s
TIMEOUT ERROR,
running time: >9.00 sec., time limit: 3.05 sec.
3.
9.000 s
TIMEOUT ERROR,
running time: >9.00 sec., time limit: 3.04 sec.