Posts

HackerRank: Minimum Distances (Easy)

Link to code challenge function minimumDistances(a) { let obj = {}; let shortest = Infinity; for (let i = 0; i

HackerRank: Equalize the Array (Easy)

Link to code challenge function equalizeArray(arr) { let count = {}; let greatest = 1; for (let num of arr) { if (count.hasOwnProperty(num)) { count[num]++; if (count[num] > greatest) greatest = count[num]; } else count[num] = 1; } return arr.length - greatest; }

HackerRank: Cut the sticks (Easy)

Link to code challenge function cutTheSticks(arr) { let sticksLeft = []; while (arr.length > 0) { sticksLeft.push(arr.length); arr.sort((a, b) => b - a); let lowest = arr[arr.length - 1]; for (let i = arr.length - 1; i >= 0; i--) { if (arr[i] === lowest) arr.splice(i, 1); else arr[i] -= lowest; } } return sticksLeft; }

HackerRank: Designer PDF Viewer (Easy)

Link to code challenge function designerPdfViewer(h, word) { let max = 0; for (let i = 0; i max) max = h[numEq]; } return max * word.length; }

HackerRank: Beautiful Days at the Movies (Easy)

Link to code challenge function beautifulDays(i, j, k) { let count = 0; for (let day = i; day

HackerRank: Counting Valleys (Easy)

Link to code challenge function countingValleys(n, s) { let level = [0]; let count = 0; for (let step of s) { if (step === "U") { level.push(level[level.length - 1] + 1); if (level[level.length - 2]