Last active
September 10, 2019 19:52
-
-
Save Ausjorg/b6add53fa0a72c6ed9876b822afde7b9 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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(A) { | |
A = new Set(A) | |
A = [...A] | |
A = A.sort(function(a,b){return a-b}) | |
var check = true | |
if (A.length == 1 && A[0] != 1) return 1 | |
for (var i = 0, len = A.length; i < len; i++) { | |
if (A[i] > 0) { | |
if (check && A[i] != 1) return 1 | |
if (A[i] + 1 != A[i + 1]) return A[i] + 1 | |
check = false | |
} | |
} | |
return 1 | |
} | |
function solution(X, A) { | |
var arr = [] | |
var range = Math.abs(X - A[0]) | |
var check = 0 | |
var arrLength = 0 | |
if (A.length == 0) { | |
return -1 | |
} | |
if (X == 1 && A[0] == 1) { | |
return 0 | |
} | |
for (var i = 0; i < range; i++) { | |
arr.push(A[0] + i) | |
} | |
arrLength = arr.length | |
for (var i = 1; i < A.length; i++) { | |
if (X == A[i]) { | |
if (check == arrLength && check != 0) { | |
return i | |
} | |
} | |
if (arr.includes(A[i])) { | |
arr.splice(A[i]-1, 1) | |
check += 1 | |
} | |
} | |
return -1 | |
} | |
function solution(A) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
A = new Set(A) | |
A = [...A] | |
A = A.sort(function(a,b){return a-b}) | |
var check = true | |
for(var i = 0; i < A.length; i++) { | |
if(A[i] > 0) { | |
if(A[i] != 1 && check) { | |
return 1 | |
} | |
if(A[i] + 1 != A[i + 1]) { | |
return A[i] + 1 | |
} | |
check = false | |
} | |
} | |
return 1 | |
} | |
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(N, A) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
var lastMax = 0; | |
var max = 0; | |
var counters = new Array (N); | |
for(j = 0; j < N; j++) counters[j] = 0; | |
for(var j=0; j < A.length; j++){ | |
if(A[j] < N + 1){ | |
i = A[j] - 1; | |
if (counters[i] < lastMax) { | |
counters[i] = lastMax; | |
} | |
counters[i]++; | |
if (max < counters[i]) { | |
max = counters[i]; // max = 1 | |
} | |
} else { | |
lastMax = max; | |
} | |
} | |
for(var j = 0; j < N; j++){ | |
if (counters[j] < lastMax) { | |
counters[j] = lastMax; | |
} | |
} | |
return counters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment