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) | |
| let [left, right] = [-1, -1]; | |
| return A.reduce((cnt,v,i)=>{ | |
| if(right < v) { | |
| cnt++; | |
| [left, right] = [v, B[i]]; | |
| } | |
| return cnt; | |
| },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, Y, D) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| return Math.ceil((Y - X)/D); | |
| } |
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; | |
| const maxArr = new Array(len).fill(0); | |
| maxArr[0] = A[0]; | |
| for(let i=1; i<len; i++){ | |
| maxArr[i] = Math.max(maxArr[i-1]+A[i],A[i]); | |
| } | |
| return Math.max(...maxArr); | |
| } |
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 A.reduceRight((acc,v)=>[Math.max(acc[0], acc[1] - v), Math.max(acc[1], v)],[0,A.pop()])[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 discs = A.map((v,i) => Object({L: i - v, R: i + v})); | |
| return discs.sort((a, b) => a.L - b.L).reduce((acc, v, i) => { | |
| for (let j = i + 1, len = A.length; j < len; j++) { | |
| if (v.R < discs[j].L) break; | |
| else acc++; | |
| } | |
| return acc > 10000000 ? discs.splice(1) && -1 : acc; | |
| }, 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 B = A.sort((a,b)=>a-b).slice(); | |
| return Math.max(B.shift()*B.shift()*B.pop(), A.pop()*A.pop()*A.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(A) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| return new Set(A).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) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| A.sort((a,b)=>a-b); | |
| return A.some((v,i)=>v+A[i+1]>A[i+2]) ? 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(S, P, Q) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| let [A,C,G,T] = [0,0,0,0]; | |
| const count = [[ A, C, G, T ]]; | |
| const map = { | |
| 'A' : () => count.push([ ++A, C, G, T ]), | |
| 'C' : () => count.push([ A, ++C, G, T ]), | |
| 'G' : () => count.push([ A, C, ++G, T ]), | |
| 'T' : () => count.push([ A, C, G, ++T ]) | |
| }; |