Skip to content

Instantly share code, notes, and snippets.

@antonybudianto
Created June 23, 2017 12:17
Show Gist options
  • Save antonybudianto/987d98fa413e3ac2907838cabbdee221 to your computer and use it in GitHub Desktop.
Save antonybudianto/987d98fa413e3ac2907838cabbdee221 to your computer and use it in GitHub Desktop.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 6.4.0)
let len = A.length
let arr = new Array(len)
for(let i=0; i<len;i++) {
let idx = A[i] - 1
if (idx < len) {
arr[idx] = arr[idx] || 0
arr[idx]++
}
}
let curMax = 0;
for(let j=0;j<len;j++) {
if (curMax < arr[j]) {
curMax = arr[j]
}
if(arr[j] === undefined) return j+1
}
return curMax+1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment