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 UndergroundSystem { | |
#stationTripLengthMap; | |
#inFlightTrips; | |
constructor() { | |
this.#stationTripLengthMap = {}; | |
this.#inFlightTrips = {}; | |
} | |
checkIn(id, stationName, t) { |
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
const VOWELS = ['a', 'e', 'i', 'o', 'u']; | |
/** | |
* @param {string} str | |
* @param {number} frameSize | |
* @return {number} | |
*/ | |
var maxVowels = function(str, frameSize) { | |
// Given a char return true if it's a vowel | |
const isVowel = (char) => VOWELS.includes(char); |
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
/** | |
* Definition for a binary tree node. | |
* class TreeNode { | |
* val: number | |
* left: TreeNode | null | |
* right: TreeNode | null | |
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : 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 canPlaceFlowers(flowerbed: number[], n: number): boolean { | |
let openPlots = 0; | |
for (let i = 0; i < flowerbed.length; ++i) { | |
if (flowerbed[i] === 1) { | |
continue; | |
} | |
const leftSideFree = (i === 0 || flowerbed[i - 1] === 0); | |
const rightSideFree = (i + 1 >= flowerbed.length || flowerbed[i + 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 shortestPathBinaryMatrix(grid: number[][]): number { | |
const getDirections = ([row, col]: [number, number]): number[][] => { | |
const canMove = ([row, col]: [number, number]) => { | |
return (row >= 0 && row < grid.length) && (col >= 0 && col < grid[row].length) | |
} | |
// Given a 3x3 matrix with row/col index of [1,1] | |
// we should return: | |
// | |
// [0, 1] == North |
OlderNewer