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(S) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const stack = []; | |
| for(let s of S){ | |
| switch(s){ | |
| case '(': | |
| stack.push(s); | |
| break; | |
| case ')': | |
| if(stack.slice(-1)[0] === '(') stack.pop(); |
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(S) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const stack = []; | |
| for(let s of S){ | |
| switch(s){ | |
| case '{': | |
| case '[': | |
| case '(': | |
| stack.push(s); | |
| break; |
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 left = A[0]; | |
| const right = A.slice(1).reduce((a,b)=>a+b); | |
| const min = Math.abs(left-right); | |
| return A.slice(1,-1).reduce(({left,right,min},cur)=> | |
| new Object({ | |
| left : left+cur, | |
| right : right-cur, | |
| min : Math.min(min, Math.abs(left-right)) |
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) | |
| return [...new Array(A.length+2).keys()].concat(A).reduce((pre,cur)=>pre^cur); | |
| } |
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, K) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| while(A.length && K--){ | |
| A.unshift(A.pop()); | |
| } | |
| return A; | |
| } |
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) | |
| A.sort((a,b)=>a-b); | |
| return A.slice(0,-2).reduce((cnt,v,i)=>{ | |
| let [Q,R] = [i+1,i+2]; | |
| while(R < A.length){ | |
| if(v + A[Q] > A[R]){ | |
| cnt += R - Q; | |
| R++; | |
| } else if(Q < R-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 result = new Set(); | |
| for(let i of A){ | |
| result.add(Math.abs(i)); | |
| } | |
| return result.size | |
| } |
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((cnt,v,i)=>hasSameFactors(v,B[i]) ? cnt+1 : cnt, 0); | |
| } | |
| function gcd(p, q){ | |
| return q ? gcd(q, p % q) : p; | |
| } | |
| function hasSameFactors(p, q){ |
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, M) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| return lcm(N,M)/M; | |
| } | |
| function gcd(p, q){ | |
| return q ? gcd(q, p % q) : p; | |
| } | |
| function lcm(p,q){ |
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(K, A) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const maxList = []; | |
| let acc = 0; | |
| let cnt = 0; | |
| for(let i =0; i<A.length; i++){ | |
| acc += A[i]; | |
| maxList[i] = acc; | |
| if(acc >= K){ | |
| cnt++; |