Created
November 13, 2020 13:16
-
-
Save alireza-mpr/df3a4065056f14536837c62360f66f18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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