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 countSort(array) { | |
const counts = {}; | |
for(const num of array) { | |
if(counts[num]) counts[num] += 1; | |
else counts[num] = 1; | |
} | |
for(let idx = 0; idx < Object.keys(counts).length - 1; idx++) { | |
counts[Object.keys(counts)[idx + 1]] += counts[Object.keys(counts)[idx]]; | |
} |
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
class Node { | |
constructor(value, children = []) { | |
this.value = value; | |
this.children = children; | |
} | |
} | |
// 3 --->7 | |
// / | | |
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
/** | |
* @param {number} N | |
* @param {number} M | |
* @param {number[]} C | |
*/ | |
function getMinCodeEntryTime(N, M, C) { | |
function minDist(i, j) { | |
const path1 = Math.abs(j - i); | |
const bigger = Math.max(i, j); | |
const smaller = Math.min(i, j); |
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
** https://leetcode.com/problems/kth-smallest-element-in-a-bst/ | |
* Definition for a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root |
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
// People representing each index: | |
// 0 - Carla, 1- Star, 2- Gabriel, 3- Ikeda, 4-Matt | |
// Each food will be represented by its initial: | |
// Banana, Goiabinha, Hersheys, Pacoquinha, Suflair | |
// The solution is a string (eg: 'BGHPS') assigning each food to a person | |
const day = [['S', 'P', 'H', 'B', 'G'], 2]; | |
const max = [['S', 'B', 'G', 'P', 'H'], 2]; | |
const sab = [['S', 'G', 'P', 'B', 'H'], 2]; | |
const gab = [['S', 'H', 'B', 'G', 'P'], 3]; | |
const coringa = [['H', 'G', 'B','P', 'S'], 1]; |
OlderNewer