A collection of classical data structures and algorithms implemented in Typescript. Click the 📹 emoji for tutorials.
Data structure series: View the entire series in order here.
Algorithms/leetcode series: View the entire series in order here
The repository's primary goal is educational. Hence, all implementations include a prolific number of comments which guide the reader.
You can use this package in your projects if you so wish. Test coverage will be kept at 100%. To install the package, use npm or yarn:
npm install dsa-ts --save
yarn add dsa-ts
- Sequences
- Priority Queues
- 📹 Binary Heap
- D-Heap
- 📹 Indexed Binary Heap
- Mergeable Heaps
- Search Trees
- Hash Tables
Following algoritms/problems compiled from Grokking, EPI, and AlgoExpert
- Array
- Sliding Window
- Two Pointers
- Fast and Slow Pointers
- Binary Search
- Merge Intervals
- Cyclic Sort
- String
- Linked List
- Linked List Reversal
- Tree
- Tree BFS
- Tree DFS
- Stacks/Queues/Monotonic Queues
- Two Heaps
- Top K Elements
- K-way Merge
- Design
- Backtracking
- Greedy
- Topological Sort
- Union Find
- Tries
- Bit Manipulation
- 509. Fibonacci Number (Easy)
- 896. Monotonic Array (Easy)
- 238. Product of Array Except Self (Medium)
- 48. Rotate Image (Medium)
- 33. Search in Rotated Sorted Array (Medium)
- 34. Find First and Last Position of Element in Sorted Array (Medium)
- 189. Rotate Array (Easy)
- 118. Pascal's Triangle (Easy)
- 54. Spiral Matrix (Medium)
- 280. Wiggle Sort (Medium)
- 36. Valid Sodoku (Medium)
- 48. Rotate Image (Medium)
- 4. Median of Two Sorted Arrays (Hard)
- 84. Largest Rectangle in Histogram (Hard)
- 1200. Minimum Absolute Difference (Easy)
- 209. Minim Size Subarray Sum (Medium)
- 904. Fruit Into Baskets (Medium)
- 3. Longest Substring Without Repeating Characters (Medium)
- 1004. Max Consecutive Ones III (Medium)
- 567. Permutation in String (Medium)
- 438. Find All Anagrams in a String (Medium)
- 46. Minimum Window Substring (Hard)
- 76. Minimum Window Substring (Hard)
- 239. Sliding Window Maximum (Hard)
- 167. Two Sum II (Easy)
- 283. Move Zeroes
- 26. Remove Duplicates from Sorted Array (Easy)
- 977. Squares of a Sorted Array (Easy)
- 15. 3Sum (Medium)
- 16. 3Sum Closest (Medium)
- 713. Subarray Product Less than K (Medium)
- 75. Sort Colors (Medium)
- 18. 4Sum (Medium)
- 845. Longest Mountain in Array (Medium)
- 844. Backspace String Compare (Easy)
- 581. Shortest Unsorted Continuous Subarray (Easy)
- 141. Linked List Cycle (Easy)
- 142. Linked List Cycle II (Easy)
- 876. Middle of the Linked List (Easy)
- 234. Palindrome Linked List (Easy)
- 143. Reorder List (Medium)
- 457. Circular Array Loop (Medium)
- 74. Search a 2D Matrix (Medium)
- 240. Search a 2D Matrix II (Medium)
- 📹 454. 4Sum II (Medium)
- 📹 875. Koko Eating Bananas (Medium)
- 📹 56. Merge Intervals (Medium)
- 📹 57. Insert Interval (Hard)
- 252 Meeting Rooms (Easy)
- 📹 253. Meeting Rooms II (Medium)
- 📹 452. Minimum Number of Arrows to Burst Balloons (Medium)
- 📹 986. Interval List Intersection (Medium)
- 📹 268. Missing Number (Easy)
- 448. Find All Numbers Disappeared in an Array (Easy)
- 📹 287. Find the Duplicate Number (Medium)
- 📹 442. Find All Duplicates in an Array (Medium)
- 41. First Missing Positive (Hard)
- 📹 20. Valid Parentheses (Easy)
- 📹 680. Valid Palindrome II (Easy)
- 📹 557. Reverse Words in a String III (Easy)
- 📹 929. Unique Email Addresses (Easy)
- 459. Repeated Substring Pattern (Easy)
- 📹 415. Add Strings (Easy)
- 14. Longest Common Prefix (Easy)
- 583. Delete Operation for Two Strings (Medium)
- 767. Reorganize String (Medium)
- 856. Score of Parentheses (Medium)
- 1249. Minimum Remove to Make Valid Parentheses (Medium)
- 1268. Search Suggestions System (Medium)
- 791. Custom Sort String (Medium)
- 890. Find and Replace Pattern (Medium)
- 678. Valid Parenthesis String (Medium)
- 227. Basic Calculator II (Medium)
- 49. Group Anagrams (Medium)
- 214. Shortest Palindrome (Hard)
- 632. Smallest Range Covering Elements from K Lists (Hard)
- 21. Merge Two Sorted Lists (Easy)
- 160. Intersection of Two Linked Lists (Easy)
- 83. Remove Duplicates from Sorted List (Easy)
- 19. Remove Nth Node From End of List (Medium)
- 138. Copy List with Random Pointer (Medium)
- 19. Remove Nth Node from End of List (Medium)
- 2. Add Two Numbers (Medium)
- 138. Copy List with Random Pointer (Medium)
- 234. Palindrome Linked List (Easy)
- 86. Partition List (Medium)
- 206. Reverse Linked List (Easy)
- 92. Reverse Linked List II (Medium)
- 61. Rotate List (Medium)
- 24. Swap Nodes in Pairs (Medium)
- 328. Odd Even Linked List (Medium)
- 25. Reverse Nodes in k-Group (Hard)
- 617. Merge Two Binary Trees (Easy)
- 226. Invert Binary Tree (Easy)
- 110. Balanced Binary Tree (Easy)
- 101. Symmetric Tree (Easy)
- 94. Binary Tree Inorder Traversal (Medium)
- 144. Binary Tree Preorder Traversal (Medium)
- 145. Binary Tree Postorder Traversal (Hard)
- 236. Lowest Common Ancestor of a Binary Tree (Medium)
- 297. Serialize and Deserialize Binary Tree (Hard)
- 145. Binary Tree Postorder Traversal Tree (Hard)
- 101. Symmetric Tree (Easy)
- 102. Binary Tree Level Order Traversal (Medium)
- 107. Binary Tree Level Order Traversal II (Easy)
- 103. Binary Tree Zigzag Level Order Traversal (Medium)
- 637. Average of Levels in Binary Tree (Easy)
- 111. Minimum Depth of Binary Tree (Easy)
- 104. Maximum Depth of Binary Tree (Easy)
- 116. Populating Next Right Pointers in Each Node (Medium)
- 199. Binary Tree Right Side View (Medium)
- 112. Path Sum (Easy)
- 100. Same Tree (Easy)
- 113. Path Sum II (Medium)
- 437. Path Sum III (Easy)
- 105. Construct Binary Tree from Preorder and Inorder Traversal (Medium)
- 114. Flatten Binary Tree to Linked List (Medium)
- 129. Sum Root to Leaf Numbers (Medium)
- 543. Diameter of a Binary Tree (Easy)
- 124. Binary Tree Maximum Path Sum (Hard)
- 98. Validate Binary Search Tree (Medium)
- 1028. Recover a Tree From Preorder Traversal (Hard)
- 496. Next Greater Element I (Easy)
- 503. Next Greater Element II (Medium)
- 901. Online Stock Span (Medium)
- 739. Daily Temperatures (Medium)
- 907. Sum of Subarray Minimums (Medium)
- 456. 132 Pattern (Medium)
- 42. Trapping Rain Water (Hard)
- 862. Shortest Subarray with Sum at Least K (Hard)
- 84. Largest Rectangle in Histogram (Hard)
- 239. Sliding Window Maximum (Hard)
- 891. Sum of Subsequence Widths (Hard)
- 295. Find Median from Data Stream (Hard)
- 502. IPO (Hard)
- 215. Kth Largest Element in an Array (Medium)
- 347. Top K Frequent Elements (Medium)
- 973. K Closest Points to Origin (Medium)
- 451. Sort Characters by Frequency (Medium)
- 767. Reorganize String (Medium)
- 658. Find K Closest Elements (Medium)
- 692. Top K Frequent Words (Medium)
- 621. Task Scheduler (Medium)
- 895. Maximum Frequency Stack (Hard)
- 1000. Minimum Cost to Merge Stones (Hard)
- 23. Merge K Sorted Lists (Hard)
- 378. Kth Smallest Element in a Sorted Matrix (Medium)
- 373. Find K Pairs with Smallest Sums (Medium)
- 146. LRU Cache (Medium)
- 155. Min Stack (Easy)
- 622. Design Circular Queue (Medium)
- 232. Implement Queue using Stacks (Easy)
- 211. Add and Search Word - Data structure design (Medium)
- 705. Design HashSet (Easy)
- 297. Serialize and Deserialize Binary Tree (Hard)
- 78. Subsets (Easy)
- 90. Subsets II (Medium)
- 46. Permutations (Medium)
- 47. Permutations II (Medium)
- 60. Permutation Sequence (Hard)
- 22. Generate Parentheses (Hard)
- 39. Combination Sum (Medium)
- 40. Combinatin Sum II (Medium)
- 216. Combination Sum III (Medium)
- 77. Combinations (Medium)
- 526. Beautiful Arrangement (Medium)
- 784. Letter Case Permutation (Easy)
- 980. Unique Paths III (Hard)
- 131. Palindrome Partitioning (Medium)
- 17. Letter Combinations of a Phone Number (Medium)
- 51. N-Queens (Hard)
- 37. Sudoker Solver (Hard)
- 79. Word Search (Medium)
- 212. Word Search II (Hard)
- 763. Partition Labels (Medium)
- 407. Queue Reconstruction by Height (Medium)
- 1046. Last Stone Weight (Easy)
- 1029. Two City Scheduling (Easy)
- 621. Task Scheduler (Medium)
- 767. Reorganize String (Medium)
- 435. Non-overlapping Intervals (Medium)
- 134. Gas Station (Medium)
- 55. Jump Game (Medium)
- 45. Jump Game II (Hard)
- 630. Course Schedule III (Hard)
- 135. Candy (Hard)
- 402. Remove K Digits (Medium)
- 314. Remove Duplicate Letters (Hard)
- 765. Couples Holding Hands (Hard)
- 207. Course Schedule (Medium)
- 210. Course Schedule II (Medium)
- 269. Alien Dictionary (Hard)
- 444. Sequence Reconstruction (Hard)
- 310. Minimum Height Trees (Medium)
- 128. Longest Consecutive Sequence (Hard)
- 200. Number of Islands (Medium)
- Graph Valid Tree
- Number of Connected Components in an Undirected Graph
- 208. Implement Trie (Prefix Tree) (Medium)
- 676. Implement Magic Dictionary (Medium)
- 677. Map Sum Pairs (Medium)
- 648. Replace Words (Medium)
- 421. Maximum XOR of Two Numbers in an Array (Medium)
- 692. Top K Frequent Words (Medium)
- 1032. Stream of Characters (Hard)
- 212. Word Search II (Hard)
- 472. Concatenated Words (Hard)
- 336. Palindrome Pairs (Hard)
- Index Pairs of a String
- Design Search Autocomplete System
- Word Squares
- 231. Power of Two (Easy)
- 201. Bitwise AND of Numbers Range (Easy)
- 461. Hamming Distance (Easy)
- 338. Counting Bits (Medium)
- 136. Single Number (Easy)
- 137. Single Number II (Medium)
- 260. Single Number III (Medium)
- 1109. Complement of Base 10 Integer (Easy)
- 832. Flipping an Image (Easy)
- 476. Number Complement (Easy)
- 784. Letter Case Permutation (Easy)
- 169. Majority Element (Easy)
- 318. Maximum Product of Word Lengths (Medium)
- 477. Total Hamming Distance (Medium)
- Fundamental Data Structures
- Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein
- Algorithm Design by Jon Kleinberg and Éva Tardos
- Algorithms by William Fiset
- Algorithms by Jeff Erickson
- Stanford CS 166
- Harvard CS 224
This repository is released under the MIT license. In short, this means you are free to use this software in any personal, open-source or commercial projects