Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution(input) {
- let map = {};
- let small = Number.MAX_SAFE_INTEGER, big = Number.MIN_SAFE_INTEGER;
- input.forEach(element => {
- map[element] = true;
- if (element < small) {
- small = element;
- }
- if (element > big) {
- big = element;
- }
- });
- for (let i = small; i < big; i++) {
- if (!map[i]) {
- return i;
- }
- }
- }
- const input = [1, 3, 6, 4, 1, 2];
- console.log(solution(input));
Add Comment
Please, Sign In to add comment