Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
🎯
Focusing on Something new!

Ali Torki ali-master

🎯
Focusing on Something new!
View GitHub Profile
@ali-master
ali-master / findAnagramGroups.ts
Created July 14, 2021 10:09
Given an array of strings, group anagrams together in Javascript
/**
* 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:
@ali-master
ali-master / maxIslandsCount.ts
Created July 13, 2021 23:03
Javascript Find max islands count in matrix
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);
@ali-master
ali-master / greedy.ts
Last active November 20, 2021 13:29
Check if we can go from top-left to the right-bottom in a Matrix which returns the path of way by javascript
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));
@ali-master
ali-master / redux-from-scratch.ts
Created July 9, 2021 19:12
A simple redux from scratch
/**
* Redux
* - getState()
* - subscribe()
* - dispatch() -> ui -> state
* - combineReducer
*
*
* - replaceReducer
* - injectReducer
@ali-master
ali-master / time-overlap.js
Created May 21, 2021 14:31
Check if two time strings have overlap in Javascript.
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)) {
@ali-master
ali-master / maybe.ts
Created April 23, 2021 22:20 — forked from vagarenko/maybe.ts
Maybe type in Typescript.
/**
* 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. */
@ali-master
ali-master / scratch_16.js
Created December 8, 2020 13:57
Find missing number in an array of numbers
// 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++) {
@ali-master
ali-master / Operator-mono-ssm.css
Created August 9, 2020 13:25
Operator mono ssm css font
@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
@ali-master
ali-master / sugarCube.js
Last active May 19, 2020 07:35
Find the the sugar cube box which it's cubes weight is different with other boxes.
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++) {
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));