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
/** | |
* This problem was asked by Robinhood. | |
Given an array of strings, group anagrams together. | |
For example, given the following array: | |
['eat', 'ate', 'apt', 'pat', 'tea', 'now'] | |
Return: |
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
function dfs(graph: Grid) { | |
let max = 0; | |
let islandsCount = 0; | |
const visited: Grid<boolean> = [[], [], [], [], []]; | |
for (let x = 0; x < graph.length; x++) { | |
for (let y = 0; y < graph[x].length; y++) { | |
if (!visited[x][y]) { | |
islandsCount = 1 + can(graph, x, y, visited); |
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
const grid: Array<Array<number>> = [ | |
[1, 0, 1, 1, 1], | |
[1, 1, 1, 0, 0], | |
[0, 1, 0, 1, 1], | |
[1, 0, 1, 1, 0], | |
[0, 0, 1, 1, 1] | |
]; | |
console.log(solveGrid(grid)); |
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
/** | |
* Redux | |
* - getState() | |
* - subscribe() | |
* - dispatch() -> ui -> state | |
* - combineReducer | |
* | |
* | |
* - replaceReducer | |
* - injectReducer |
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
function parseTimeString(str) { | |
return parseFloat(str.replace(":", ".")) | |
} | |
function hasConflict(firstTime, secondTime) { | |
const firstTimeStart = parseTimeString(firstTime.start) | |
const firstTimeEnd = parseTimeString(firstTime.end) | |
const secondTimeStart = parseTimeString(secondTime.start) | |
const secondTimeEnd = parseTimeString(secondTime.end) | |
if((firstTimeStart <= secondTimeEnd) && (secondTimeStart <= firstTimeEnd)) { |
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
/** | |
* The Maybe type encapsulates an optional value. | |
*/ | |
export class Maybe<T> { | |
/** Create an empty value. */ | |
static nothing<T>(): Maybe<T> { | |
return new Maybe<T>(undefined); | |
} | |
/** Create a non-empty value. */ |
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
// Find theoretical sum of the consecutive numbers using a variation of Gauss Sum. | |
// Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2]; | |
// N is the upper bound and M is the lower bound | |
function missingNumber(n) { | |
let upperBound = 0; | |
let lowerBound = 99999999; | |
let sum = 0; | |
for (let i = 0; i < n.length; i++) { |
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
@font-face { | |
font-family: 'Operator Mono SSm'; | |
src: url(data:application/x-font-woff;base64,d09GRgABAAAAAGpyABIAAAAAytgAAQAAAABoTAAAAiYAAAaTAAAAAAAAAABHREVGAABnkAAAAB0AAAAeACgA5UdQT1MAAGewAAAAQAAAAFgsnhyBR1NVQgAAZ/AAAABbAAAAhOs/LbZPUy8yAAACCAAAAFcAAABgWBrmPWNtYXAAAAO8AAACcQAAA2iGH4kRY3Z0IAAACIAAAABkAAAAZBmhB5pmcGdtAAAGMAAAAQIAAAFzBlmcN2dhc3AAAGeEAAAADAAAAAwADwAaZ2x5ZgAACqQAAFZbAACtACBUat1oZG14AAADtAAAAAgAAAAIAAAA5GhlYWQAAAGUAAAAMwAAADYHchYnaGhlYQAAAcgAAAAeAAAAJAZuAsFobXR4AAACYAAAAVEAAANiAJlRdmxvY2EAAAjkAAABwAAAAcAXX0J0bWF4cAAAAegAAAAgAAAAIAMPBGtuYW1lAABhAAAABIkAAAvHAxl5pXBvc3QAAGWMAAAB9wAAApzNbPx+cHJlcAAABzQAAAFKAAAB98jebkJ42mNgZGBgYPQ5c3mdAkc8v81XBnnmF0ARhku3Dt2B06z/zjK1MH8EcjkYmECiALPzD1UAeNpjYGRgYD7w34JBg2kbAxAwtTAwMqCCSwBdKgQ1AAAAAQAAAN8CEAAfAEcABAABAAAAAAAKAAACAAISAAIAAXjaY2BmKmR0ZWBlYGFqZmr+f5dhE4hmcGGMY/BhzGVgYGJg4GQAgwUMDPYCDAxRDFDgoeacD6R4H3IzK/y3YDjBfIDhA5DfDZJjUmDaAKQUGJgAC0sPiAB42m3SvUtCYRTH8XMvhIND1NTS2pBFVmREUEFJg4tKSRkhFmYUQdrLkIQQNDUEZrNrm1tLq/9EU1uLQQm193vqG8TlKh/OfXleznPO9Uesz/j5lR9f |
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
function findDifferentSugarCube(boxes) { | |
const selectBoxesOfCubes = boxes.reduce((acc, current, index) => { | |
acc.push(current.slice(0, index + 1)); | |
return acc; | |
}, []); | |
let weight = 0; | |
let no = 0; | |
for (let i = 0; i < selectBoxesOfCubes.length; i++) { |
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
function redGreenBlue(r, g, b) { | |
const leftArray = [] | |
const createdGroupsNo = []; | |
function createGroup (column, type){ | |
if (column % 3 <= 2) { | |
if (column >= 3) { | |
column -= 3; | |
type && createdGroupsNo.push(Array(3).fill(type)); |