An open API service indexing awesome lists of open source software.

https://github.com/shkvik/nodejs-algorithms

This repository is a collection of various algorithms implemented in Node.js using TypeScript.
https://github.com/shkvik/nodejs-algorithms

algorithms bfs dfs nodejs sorts typescript

Last synced: 9 months ago
JSON representation

This repository is a collection of various algorithms implemented in Node.js using TypeScript.

Awesome Lists containing this project

README

          

# nodejs-algorithms
This repository is a collection of various algorithms implemented in Node.js using TypeScript.
## LeetCode Problems

| № | Problem Title | LeetCode | Solution | Ideal O(Time) | Ideal O(Space)
|----|----------------------------------------------------------------------|------------------------------------------------------------------- |-------------------- |-------------- |-----------------
| 1 | Two Sum | [Link](https://leetcode.com/problems/two-sum) |[Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/two-sum.ts) | $O(n)$ | $O(n)$
| 2 | Longest Substring Without Repeating Characters | [Link](https://leetcode.com/problems/longest-substring-without-repeating-characters) |[Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/longest-substring.string.ts) | $O(n)$ | $O(min(m,n))$
| 3 | Longest Palindromic Substring | [Link](https://leetcode.com/problems/longest-palindromic-substring) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/longest-palindromic-substring.ts)| $O(n^2)$ | $O(n)$
| 4 | Palindrome Number | [Link](https://leetcode.com/problems/palindrome-number) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/math/palindrome-number.ts) | $O(log_{10}(n))$ | $O(1)$
| 5 | Valid Parentheses | [Link](https://leetcode.com/problems/valid-parentheses) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/stack/valid-parentheses.ts) | $O(n)$ | $O(n)$
| 6 | Generate Parentheses | [Link](https://leetcode.com/problems/generate-parentheses) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/backtracking/generate-parentheses.ts) | $O(4^n / \sqrt{n})$ | $O(4^n / \sqrt{n})$
| 7 | Merge k Sorted Lists | [Link](https://leetcode.com/problems/merge-k-sorted-lists) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/linked-list/merge-k-sorted-lists.ts) | $O(n \log k)$ | $O(k)$
| 8 | Remove Element | [Link](https://leetcode.com/problems/remove-element) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/remove-element.ts) | $O(n)$ | $O(1)$
| 9 | Find the Index of the First Occurrence in a String | [Link](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/first-occurrence-in-string.ts) | $O(n \cdot m)$ | $O(1)$
| 10 | Search in Rotated Sorted Array | [Link](https://leetcode.com/problems/search-in-rotated-sorted-array) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/search-in-rotated-array.ts) | $O(\log n)$ | $O(1)$
| 11 | Trapping Rain Water | [Link](https://leetcode.com/problems/trapping-rain-water) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/trapping-rain-water.ts) | $O(n)$ | $O(1)$
| 12 | Group Anagrams | [Link](https://leetcode.com/problems/group-anagrams) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/group-anagrams.ts) | $O(n \cdot k \log k)$ | $O(nk)$
| 13 | Merge Intervals | [Link](https://leetcode.com/problems/merge-intervals) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/merge-intervals.ts) | $O(n \log n)$ | $O(n)$
| 14 | Simplify Path | [Link](https://leetcode.com/problems/simplify-path) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/stack/simplify-path.ts) | $O(n)$ | $O(n)$
| 15 | Minimum Window Substring | [Link](https://leetcode.com/problems/minimum-window-substring) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/minimum-window-substring.ts) | $O(n)$ | $O(|S| + |T|)$
| 16 | Merge Sorted Array | [Link](https://leetcode.com/problems/merge-sorted-array) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/merge-sorted-array.ts) | $O(n+m)$ | $O(1)$
| 17 | Validate Binary Search Tree | [Link](https://leetcode.com/problems/validate-binary-search-tree) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/validate-bst.ts) | $O(n)$ | $O(n)$
| 18 | Symmetric Tree | [Link](https://leetcode.com/problems/symmetric-tree) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/symmetric-tree.ts) | $O(n)$ | $O(n)$
| 19 | Maximum Depth of Binary Tree | [Link](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/maximum-depth-binary-tree.ts) | $O(n)$ | $O(h)$
| 20 | Best Time to Buy and Sell Stock | [Link](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/best-time-to-buy-and-sell.ts) | $O(n)$ | $O(1)$
| 21 | Binary Tree Maximum Path Sum | [Link](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/binary-tree-maximum-path-sum.ts) | $O(n)$ | $O(h)$
| 22 | Valid Palindrome | [Link](https://leetcode.com/problems/valid-palindrome) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/valid-palindrome.ts) | $O(n)$ | $O(1)$
| 23 | Single Number | [Link](https://leetcode.com/problems/single-number) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/single-number.ts) | $O(n)$ | $O(1)$
| 24 | LRU Cache | [Link](https://leetcode.com/problems/lru-cache) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/linked-list/lru-cache.ts) | $O(1)$ | $O(n)$
| 25 | Evaluate Reverse Polish Notation | [Link](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/stack/evaluate-reverse-polish.ts) | $O(n)$ | $O(n)$
| 26 | Min Stack | [Link](https://leetcode.com/problems/min-stack) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/stack/min-stack.ts) | $O(1)$ | $O(n)$
| 27 | One Edit Distance | [Link](https://leetcode.com/problems/one-edit-distance) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/one-edit-distance.ts) | $O(n)$ | $O(1)$
| 28 | Majority Element | [Link](https://leetcode.com/problems/majority-element) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/majority-element.ts) | $O(n)$ | $O(1)$
| 29 | Binary Tree Right Side View | [Link](https://leetcode.com/problems/binary-tree-right-side-view) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/binary-tree-right-side-view.ts) | $O(n)$ | $O(h)$
| 30 | Number of Islands | [Link](https://leetcode.com/problems/number-of-islands) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/graph/number-of-islands.ts) | $O(n \cdot m)$ | $O(n \cdot m)$
| 31 | Isomorphic Strings | [Link](https://leetcode.com/problems/isomorphic-strings) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/isomorphic-strings.ts) | $O(n)$ | $O(n)$
| 32 | Reverse Linked List | [Link](https://leetcode.com/problems/reverse-linked-list) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/linked-list/reverse-linked-list.ts) | $O(n)$ | $O(1)$
| 33 | Summary Ranges | [Link](https://leetcode.com/problems/summary-ranges) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/summary-ranges.ts) | $O(n)$ | $O(1)$
| 34 | Lowest Common Ancestor of a Binary Tree | [Link](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/lowest-common-ancestor.ts) | $O(n)$ | $O(h)$
| 35 | Product of Array Except Self | [Link](https://leetcode.com/problems/product-of-array-except-self) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/product-of-array-except-self.ts) | $O(n)$ | $O(1)$
| 36 | Meeting Rooms II | [Link](https://leetcode.com/problems/meeting-rooms-ii) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/heap/meeting-rooms-ii.ts) | $O(n \log n)$ | $O(n)$
| 37 | Move Zeroes | [Link](https://leetcode.com/problems/move-zeroes) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/move-zeroes.ts) | $O(n)$ | $O(1)$
| 38 | Longest Increasing Subsequence | [Link](https://leetcode.com/problems/longest-increasing-subsequence) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/longest-increasing-subsequence.ts) | $O(n \log n)$ | $O(n)$
| 39 | Remove Invalid Parentheses | [Link](https://leetcode.com/problems/remove-invalid-parentheses) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/remove-invalid-parentheses.ts) | $O(2^n)$ | $O(n)$
| 40 | Reconstruct Itinerary | [Link](https://leetcode.com/problems/reconstruct-itinerary) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/graph/reconstruct-itinerary.ts) | $O(E \log E)$ | $O(V + E)$
| 41 | Longest Substring with At Most K Distinct Characters | [Link](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/longest-substring-k-distinct.ts)| $O(n)$ | $O(k)$
| 42 | Flatten Nested List Iterator | [Link](https://leetcode.com/problems/flatten-nested-list-iterator) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/iterator/flatten-nested-list.ts) | $O(n)$ | $O(n)$
| 43 | Intersection of Two Arrays | [Link](https://leetcode.com/problems/intersection-of-two-arrays) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/intersection-of-two-arrays.ts) | $O(n \log n)$ | $O(n)$
| 44 | Intersection of Two Arrays II | [Link](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/intersection-of-two-arrays-ii.ts) | $O(n \log n)$ | $O(n)$
| 45 | Line Reflection | [Link](https://leetcode.com/problems/line-reflection) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/geometry/line-reflection.ts) | $O(n)$ | $O(n)$
| 46 | Design Hit Counter | [Link](https://leetcode.com/problems/design-hit-counter) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/design/design-hit-counter.ts) | $O(1)$ | $O(w)$
| 47 | Insert Delete GetRandom O(1) | [Link](https://leetcode.com/problems/insert-delete-getrandom-o1) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/design/insert-delete-getrandom.ts) | $O(1)$ | $O(n)$
| 48 | Is Subsequence | [Link](https://leetcode.com/problems/is-subsequence) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/is-subsequence.ts) | $O(n)$ | $O(1)$
| 49 | Find All Anagrams in a String | [Link](https://leetcode.com/problems/find-all-anagrams-in-a-string) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/find-all-anagrams.ts) | $O(n)$ | $O(k)$
| 50 | String Compression | [Link](https://leetcode.com/problems/string-compression) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/string-compression.ts) | $O(n)$ | $O(1)$
| 51 | Max Consecutive Ones | [Link](https://leetcode.com/problems/max-consecutive-ones) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/max-consecutive-ones.ts) | $O(n)$ | $O(1)$
| 52 | Max Consecutive Ones II | [Link](https://leetcode.com/problems/max-consecutive-ones-ii) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/max-consecutive-ones-ii.ts) | $O(n)$ | $O(1)$
| 53 | Subarray Sum Equals K | [Link](https://leetcode.com/problems/subarray-sum-equals-k) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/subarray-sum-equals-k.ts) | $O(n)$ | $O(n)$
| 54 | Permutation in String | [Link](https://leetcode.com/problems/permutation-in-string) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/permutation-in-string.ts) | $O(n)$ | $O(1)$
| 55 | Find Duplicate Subtrees | [Link](https://leetcode.com/problems/find-duplicate-subtrees) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/tree/find-duplicate-subtrees.ts) | $O(n)$ | $O(n)$
| 56 | Robot Return to Origin | [Link](https://leetcode.com/problems/robot-return-to-origin) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/robot-return-to-origin.ts) | $O(n)$ | $O(1)$
| 57 | Find K Closest Elements | [Link](https://leetcode.com/problems/find-k-closest-elements) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/find-k-closest-elements.ts) | $O(\log n + k)$| $O(1)$
| 58 | Valid Palindrome II | [Link](https://leetcode.com/problems/valid-palindrome-ii) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/string/valid-palindrome-ii.ts) | $O(n)$ | $O(1)$
| 59 | Maximize Distance to Closest Person | [Link](https://leetcode.com/problems/maximize-distance-to-closest-person) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/maximize-distance-to-closest.ts) | $O(n)$ | $O(1)$
| 60 | Number of Recent Calls | [Link](https://leetcode.com/problems/number-of-recent-calls) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/queue/number-of-recent-calls.ts) | $O(1)$ | $O(w)$
| 61 | Squares of a Sorted Array | [Link](https://leetcode.com/problems/squares-of-a-sorted-array) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/squares-of-a-sorted-array.ts) | $O(n)$ | $O(n)$
| 62 | Interval List Intersections | [Link](https://leetcode.com/problems/interval-list-intersections) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/interval-list-intersections.ts) | $O(n)$ | $O(1)$
| 63 | Max Consecutive Ones III | [Link](https://leetcode.com/problems/max-consecutive-ones-iii) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/max-consecutive-ones-iii.ts) | $O(n)$ | $O(1)$
| 64 | Sort the Matrix Diagonally | [Link](https://leetcode.com/problems/sort-the-matrix-diagonally) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/matrix/sort-matrix-diagonally.ts) | $O(n \cdot m)$ | $O(n \cdot m)$
| 65 | Destination City | [Link](https://leetcode.com/problems/destination-city) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/graph/destination-city.ts) | $O(n)$ | $O(n)$
| 66 | Longest Subarray of 1's After Deleting One Element | [Link](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/longest-subarray-after-delete.ts) | $O(n)$ | $O(1)$
| 67 | Design an ATM Machine | [Link](https://leetcode.com/problems/design-an-atm-machine) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/design/design-atm-machine.ts) | $O(1)$ | $O(n)$
| 68 | Promise Pool | [Link](https://leetcode.com/problems/promise-pool) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/concurrency/promise-pool.ts) | $O(n)$ | $O(k)$
| 69 | Flatten Deeply Nested Array | [Link](https://leetcode.com/problems/flatten-deeply-nested-array) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/flatten-deeply-nested-array.ts) | $O(n)$ | $O(n)$
| 70 | Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/array/find-prefix-common-array.ts) | $O(n)$ | $O(1)$
| 71 | Event Emitter | [Link](https://leetcode.com/problems/event-emitter) | [Link](https://github.com/shkvik/nodejs-algorithms/blob/main/src/design/event-emitter.ts) | $O(n)$ | $O(1)$