Java Perm Missing Element
import java.util.Arrays;
public class Solution {
public static int permMissingElement(int[] a) {
int[] sorted = a.clone();
Arrays.sort(sorted);
for (int k = 0; k < sorted.length; k++) {
if (sorted[k] != k + 1) {
return k + 1;
}
}
return sorted.length + 1;
}
}
This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.