Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 15, 2018 16:51
Show Gist options
  • Save adicuco/27b38551dfc8f58f372528137a2eca19 to your computer and use it in GitHub Desktop.
Save adicuco/27b38551dfc8f58f372528137a2eca19 to your computer and use it in GitHub Desktop.
100% solution for Permutation Missing Element on Codility
function solution(A) {
if (A.length == 0) return 1;
var min = 100000;
var max = 0;
var B = [];
for (var i = 0; i < A.length; i++) {
B[A[i]] = 0;
if (A[i] > max) max = A[i];
if (A[i] < min) min = A[i];
}
if (min != 1) return 1;
if (max == A.length) return max + 1;
for (; min <= max; min++) {
if (typeof B[min] === "undefined") return min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment