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(N) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| let [cnt, i] = [0, 1]; | |
| while (Math.pow(i,2) <= N){ | |
| if (!(N % i)) cnt += Math.pow(i,2) === N ? 1 : 2; | |
| i++; | |
| } | |
| return cnt | |
| } |
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) | |
| let [...f] = fib(A.length+1); | |
| let mins = new Array(A.length+1); | |
| for (let i = 0; i < mins.length; ++i) { | |
| if (i < A.length && A[i] === 0) { | |
| mins[i] = -1; | |
| continue; | |
| } |
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(M, A) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| let sum = 0; | |
| let front = 0; | |
| let back = 0; | |
| const seen = new Array(M+1).fill(false); | |
| while (front < A.length && back < A.length){ | |
| while (front < A.length && seen[A[front]] !== true){ | |
| sum += (front-back+1); | |
| seen[A[front]] = true; |
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 ROLL = 6; | |
| const sol = new Array(A.length+ROLL).fill(-Infinity); | |
| sol[ROLL] = A[0]; | |
| for(let i =ROLL+1; i<A.length+ROLL; i++){ | |
| let max = -Infinity; | |
| for(let pre =0; pre<ROLL; pre++){ | |
| max = Math.max(max, sol[i-pre-1]); | |
| } |
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 map = A.reduce((map,v,i)=>{ | |
| map[v] ? map[v].push(i) : map[v] = [i]; | |
| return map; | |
| },{}); | |
| for(let item in map){ | |
| if(map[item].length > A.length/2) return map[item][0]; | |
| } |
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(X, A) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const marks = new Set(); | |
| return A.reduce((idx,v,i)=>{ | |
| v <= X && marks.add(v); | |
| return marks.size === X ? A.splice(1) && i : idx; | |
| },-1); | |
| } |
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(H) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const s = []; | |
| return H.reduce((cnt,h)=>{ | |
| while (s.length && s.slice(-1)[0] > h) s.pop(); | |
| return s.length && s.slice(-1)[0] === h ? cnt : s.push(h) && cnt+1; | |
| },0); | |
| } |
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, B) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| return A.reduce((s, v, i) => { | |
| while (s.length && B[i] - B[s.slice(-1)[0]] === -1 && A[s.slice(-1)[0]] < v) s.pop(); | |
| (s.length && B[i] - B[s.slice(-1)[0]] !== -1 || !s.length) && s.push(i); | |
| return s; | |
| },[]).length; | |
| } |
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(N) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| return N.toString(2).split('1').slice(1,-1).reduce((max,v)=>Math.max(max,v.length),0); | |
| } |
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 len = A.length+1; | |
| const check = []; | |
| for(let a of A){ | |
| check[a] = true; | |
| } | |
| for(let i = 1; i<len; i++){ | |
| if(!check[i]) return i; | |
| } |
NewerOlder