public class TapeEquilibrium {
/*
* 100% solution
* https://codility.com/demo/results/demo3VDKT8-AG5/
*/
public int solution(int[] A) {
int start = A[0];
int end = sum(A, 1);
int minDif = Math.abs(start - end);
for (int index = 1; index < A.length-1; index++) {
start += A[index];
end -= A[index];
if (Math.abs(start - end) < minDif)
minDif = Math.abs(start - end);
}
return minDif;
}
public int sum(int[] A, int P) {
int result = A[P];
for ( ; P < A.length-1; P++)
result += A[P+1];
return result;
}
}
import java.util.*;
public class PermMissingElem {
/*
* 100% solution
* https://codility.com/demo/results/demoRZDAXR-HJX/
*/
public int solution(int[] A) {
int missingNum = 0;
if (A.length != 0) {
Arrays.sort(A);
for (int currentNum : A) {
if (++missingNum != currentNum)
return missingNum;
}
}
return ++missingNum;
}
}
public class FrgJump {
/*
* 100% solution
* https://codility.com/demo/results/demoD644JF-Z36/
*/
public int solution(int X, int Y, int D) {
int distance = Y - X;
return (distance % D == 0) ? (distance / D) : ((distance / D) + 1);
}
}