This file contains 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
// In a given array, find the subset of maximal sum in which the distance between consecutive elements is at most 6. | |
// https://codility.com/programmers/lessons/17-dynamic_programming/number_solitaire/ | |
// 100% for both performance & correctness | |
function solution(A) { | |
// The basic idea: | |
// We can compute the best sum of "i" (t[i]) based on the previous best sums! | |
// So let's store the best sum for each element "i" in this array: |
This file contains 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
// 100% solution for task: https://codility.com/programmers/lessons/15-caterpillar_method/abs_distinct/ | |
// | |
function solution(A) { | |
var nums = {} | |
for (i of A) { | |
nums[Math.abs(i)] = 1; | |
} | |
This file contains 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
### ES5: | |
var Rectangle = function (w, h) { | |
this.width = w; | |
this.height = h; | |
this.area = function() { | |
return calcArea(); |
OlderNewer