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
| # docker-compose.yml | |
| version: "3.8" | |
| services: | |
| mongo: | |
| image: mongo:5.0 | |
| container_name: mongo | |
| environment: | |
| - MONGO_INITDB_ROOT_USERNAME=root | |
| - MONGO_INITDB_ROOT_PASSWORD=password | |
| restart: unless-stopped |
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
| // classic example of "Sliding Window" Technique | |
| // Please refer to this video explanation: https://www.youtube.com/watch?v=U1q16AFcjKs | |
| (() => { | |
| function smallestSubstringContaining(bigString: string, smallString: string) { | |
| // create a hash out of smallString | |
| const hash: { [key: string]: number } = {}; | |
| for (let char of smallString) { | |
| hash[char] = (hash[char] || 0) + 1; | |
| } | |
| let [left, right] = [0, 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
| class BST { | |
| value: number; | |
| left: BST | null; | |
| right: BST | null; | |
| constructor(value: number) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| } |
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
| //Given an array of integers (containing positive and negative value), | |
| // find the maximum sum of a contiguous SubArray. | |
| // Detail: https://github.com/hawaijar/FireLeetcode/blob/feature/algoexpert/Famous%20Algorithms/KadaneAlgorithm/README.md | |
| (() => { | |
| function kadaneAlgorithm(array: number[]) { | |
| // base case | |
| if (array.length === 0) { | |
| return 0; | |
| } | |
| if (array.length <= 1) { |
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
| // write a function that takes X by X array of arrays of numbers | |
| // as well two x/y combinations and have it return the shortest | |
| // length (you don't need to track the actual path) from point A | |
| // to point B. | |
| // | |
| // the numbers in the maze array represent as follows: | |
| // 0 – open space | |
| // 1 - closed space, cannot pass through. a wall | |
| // 2 - one of the two origination points | |
| interface Point { |
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
| export class BinaryTreeNode { | |
| value: number; | |
| left: BinaryTreeNode | null; | |
| right: BinaryTreeNode | null; | |
| constructor(value: number) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| } |
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
| import { | |
| BinaryTreeNode, | |
| insertLevelOrder, | |
| preOrder, | |
| inOrder, | |
| postOrder, | |
| } from "../BinaryTree"; | |
| let array1 = [1, 2, 3, 4, 5, 6, 7]; | |
| let array2 = [1, 2, 3, 4, 5, 6, 6, 6, 6]; |
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 swap(array: number[], i: number, j: number) { | |
| [array[i], array[j]] = [array[j], array[i]]; | |
| } | |
| // One way of doing partition (left to right scanning) | |
| function partition1(array: number[], low: number, high: number): number { | |
| let index = low - 1; // always points to the last element <= pivot | |
| const pivotIndex = high; | |
| const pivot = array[pivotIndex]; | |
| for (let i = low; i < high; i++) { | |
| if (array[i] <= pivot) { |
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
| import { quickSort, mergeSort } from "../index"; | |
| describe("QuickSort Testing", () => { | |
| it("should sort array[1,3,4,5,2,1]", () => { | |
| const array = [1, 3, 4, 5, 2, 1]; | |
| const sortedArray = array.sort((a, b) => a - b); | |
| quickSort(array); | |
| expect(array).toEqual(sortedArray); | |
| }); | |
| it("should sort array[5, 4, 3, 2, 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
| export function permutationsOfString(str: string): string[] { | |
| const result: string[] = []; | |
| function permute(prefix: string = "", string: string) { | |
| if (prefix.length === str.length) { | |
| result.push(prefix); | |
| return; | |
| } | |
| for (let i = 0; i < string.length; i++) { | |
| permute(prefix + string[i], string.slice(0, i) + string.slice(i + 1)); |