Skip to content

Instantly share code, notes, and snippets.

@alireza-mpr
Created November 13, 2020 13:16
Show Gist options
  • Select an option

  • Save alireza-mpr/df3a4065056f14536837c62360f66f18 to your computer and use it in GitHub Desktop.

Select an option

Save alireza-mpr/df3a4065056f14536837c62360f66f18 to your computer and use it in GitHub Desktop.
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const sorted = [...new Set(A)];
var positives = sorted.filter(p=>p>0).sort((x,y)=>x-y);
if(positives.length==0) return 1;
for(let cntr=0; cntr<positives.length; cntr++)
if(cntr+1 != positives[cntr])
return cntr+1;
return positives[positives.length-1] + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment