Skip to content

codebybilal18/dsa-typescript

Repository files navigation

DSA in TypeScript — LeetCode, Blind 75 & Grind 75 Solutions

Clean Data Structures and Algorithms (DSA) solutions in TypeScript — the complete Blind 75, organized by pattern, every problem with a Big-O analysis and Vitest tests. Built for coding interview and LeetCode prep.

DSA in TypeScript is a structured, interview-focused collection of Data Structures & Algorithms solutions written in modern TypeScript. Every problem is grouped by the pattern it teaches (Two Pointers, Sliding Window, Binary Search, Trees, Graphs, Dynamic Programming, and more), and each solution ships with a problem description, worked examples, an approach write-up, time/space complexity, and passing unit tests. If you're grinding LeetCode, working through the Blind 75 / NeetCode 150, or following a Grind 75 style plan and prefer TypeScript / JavaScript over Python or C++, this repo is for you.

Topics: dsa · typescript · algorithms · data-structures · leetcode · blind-75 · grind-75 · neetcode · coding-interview · interview-prep

Who is this for

  • Engineers preparing for a coding interview who want idiomatic TypeScript references instead of Python.
  • Anyone working through Blind 75, NeetCode 150, or a Grind 75 roadmap and wanting tested, readable solutions.
  • Learners who want each DSA problem tied to a reusable pattern with a clear Big-O breakdown.

Getting started

npm install        # install dev deps (typescript, vitest)
npm test           # run every test once
npm run test:watch # watch mode
npm run typecheck  # type-check without emitting

Repository layout

src/
  lib/                 shared helpers (ListNode, TreeNode, builders)
  arrays/
    two-sum.ts         solution + description + Big-O
    two-sum.test.ts    Vitest tests for that solution
  two-pointers/
  sliding-window/
  ...

Each problem lives in its own pattern folder as a pair of files:

  • <problem>.ts — the solution, headed by a doc comment with the problem link, description, examples, the approach, and time/space complexity.
  • <problem>.test.ts — Vitest cases covering the examples plus edge cases.

Solution file convention

Every solution file starts with a header comment shaped like this:

/**
 * <Number>. <Title>  (<Difficulty>)
 * Link: https://leetcode.com/problems/...
 *
 * <Problem description in a sentence or two.>
 *
 * Example:
 *   Input:  ...
 *   Output: ...
 *
 * Approach:
 *   <How the solution works, why it is correct.>
 *
 * Time:  O(...)
 * Space: O(...)
 */

Patterns cheat sheet

Pattern Use it when… Tell-tale signals Typical complexity
Arrays / Hashing You need O(1) lookups, counting, or dedup "seen before?", frequency, complement O(n) time / O(n) space
Two Pointers Sorted array/string, pair or partition scanning "pair sums to X", palindrome, in-place move O(n) time / O(1) space
Sliding Window Contiguous subarray/substring optimum "longest/shortest subarray with…", window constraint O(n) time / O(k) space
Fast & Slow Pointers Cycle detection, middle of list linked-list cycle, "find the duplicate" O(n) time / O(1) space
Binary Search Sorted data or a monotonic answer space "min/max that satisfies…", O(log n) required O(log n) time
Stack Match/undo/nearest-smaller-or-greater parentheses, "next greater element", monotonic O(n) time / O(n) space
Heap / Top-K K largest/smallest, streaming order stats "top K", "median", scheduling O(n log k) time
Linked List In-place pointer surgery reverse, merge, reorder O(n) time / O(1) space
Trees (DFS/BFS) Hierarchical data, path/level questions traversal, depth, "level order" O(n) time / O(h) space
Graphs (BFS/DFS) Connectivity, shortest unweighted path grids, islands, "can you reach…" O(V + E) time
Backtracking Enumerate all combinations/permutations "all subsets", "generate", constraint search O(branch^depth)
Dynamic Programming Overlapping subproblems + optimal substructure "number of ways", "min/max cost", "can you…" O(states × transition)
Greedy Local optimal choice yields global optimum intervals, scheduling, "minimum number of…" O(n log n) time
Intervals Overlapping ranges "merge", "insert", "meeting rooms" O(n log n) time
Tries Prefix queries over a set of strings autocomplete, "starts with", word search O(L) per op
Bit Manipulation Set logic, parity, space-tight state XOR tricks, masks, "single number" O(n) time / O(1) space

Progress

Legend — 🟢 Easy · 🟡 Medium · 🔴 Hard

# Pattern Problem Difficulty Solution
1 Arrays / Hashing Two Sum 🟢 Easy two-sum.ts
217 Arrays / Hashing Contains Duplicate 🟢 Easy contains-duplicate.ts
242 Hash Map Valid Anagram 🟢 Easy valid-anagram.ts
49 Hash Map Group Anagrams 🟡 Medium group-anagrams.ts
238 Arrays / Hashing Product of Array Except Self 🟡 Medium product-except-self.ts
121 Sliding Window Best Time to Buy and Sell Stock 🟢 Easy best-time-to-buy-sell-stock.ts
125 Two Pointers Valid Palindrome 🟢 Easy valid-palindrome.ts
167 Two Pointers Two Sum II 🟡 Medium two-sum-ii.ts
15 Two Pointers 3Sum 🟡 Medium three-sum.ts
11 Two Pointers Container With Most Water 🟡 Medium container-with-most-water.ts
20 Stack Valid Parentheses 🟢 Easy valid-parentheses.ts
704 Binary Search Binary Search 🟢 Easy binary-search.ts
33 Binary Search Search in Rotated Sorted Array 🟡 Medium search-rotated-sorted-array.ts
206 Linked List Reverse Linked List 🟢 Easy reverse-linked-list.ts
21 Linked List Merge Two Sorted Lists 🟢 Easy merge-two-sorted-lists.ts
141 Linked List Linked List Cycle 🟢 Easy linked-list-cycle.ts
226 Trees Invert Binary Tree 🟢 Easy invert-binary-tree.ts
104 Trees Maximum Depth of Binary Tree 🟢 Easy maximum-depth.ts
100 Trees Same Tree 🟢 Easy same-tree.ts
98 Trees Validate Binary Search Tree 🟡 Medium validate-bst.ts
102 BFS / DFS Binary Tree Level Order Traversal 🟡 Medium level-order-traversal.ts
200 Graphs Number of Islands 🟡 Medium number-of-islands.ts
207 Graphs Course Schedule 🟡 Medium course-schedule.ts
78 Backtracking Subsets 🟡 Medium subsets.ts
39 Backtracking Combination Sum 🟡 Medium combination-sum.ts
46 Backtracking Permutations 🟡 Medium permutations.ts
3 Sliding Window Longest Substring Without Repeating Characters 🟡 Medium longest-substring-without-repeating.ts
155 Stack Min Stack 🟡 Medium min-stack.ts
215 Heap Kth Largest Element in an Array 🟡 Medium kth-largest-element.ts
347 Heap Top K Frequent Elements 🟡 Medium top-k-frequent.ts
70 Dynamic Programming Climbing Stairs 🟢 Easy climbing-stairs.ts
198 Dynamic Programming House Robber 🟡 Medium house-robber.ts
322 Dynamic Programming Coin Change 🟡 Medium coin-change.ts
300 Dynamic Programming Longest Increasing Subsequence 🟡 Medium longest-increasing-subsequence.ts
56 Intervals Merge Intervals 🟡 Medium merge-intervals.ts
57 Intervals Insert Interval 🟡 Medium insert-interval.ts
208 Tries Implement Trie (Prefix Tree) 🟡 Medium implement-trie.ts
53 Dynamic Programming Maximum Subarray 🟡 Medium maximum-subarray.ts
152 Dynamic Programming Maximum Product Subarray 🟡 Medium maximum-product-subarray.ts
153 Binary Search Find Minimum in Rotated Sorted Array 🟡 Medium find-min-rotated.ts
128 Arrays / Hashing Longest Consecutive Sequence 🟡 Medium longest-consecutive-sequence.ts
191 Bit Manipulation Number of 1 Bits 🟢 Easy number-of-1-bits.ts
338 Bit Manipulation Counting Bits 🟢 Easy counting-bits.ts
268 Bit Manipulation Missing Number 🟢 Easy missing-number.ts
190 Bit Manipulation Reverse Bits 🟢 Easy reverse-bits.ts
371 Bit Manipulation Sum of Two Integers 🟡 Medium sum-of-two-integers.ts
1143 Dynamic Programming Longest Common Subsequence 🟡 Medium longest-common-subsequence.ts
139 Dynamic Programming Word Break 🟡 Medium word-break.ts
377 Dynamic Programming Combination Sum IV 🟡 Medium combination-sum-iv.ts
213 Dynamic Programming House Robber II 🟡 Medium house-robber-ii.ts
91 Dynamic Programming Decode Ways 🟡 Medium decode-ways.ts
62 Dynamic Programming Unique Paths 🟡 Medium unique-paths.ts
55 Dynamic Programming Jump Game 🟡 Medium jump-game.ts
133 Graphs Clone Graph 🟡 Medium clone-graph.ts
417 Graphs Pacific Atlantic Water Flow 🟡 Medium pacific-atlantic.ts
323 Graphs Number of Connected Components 🟡 Medium number-of-connected-components.ts
261 Graphs Graph Valid Tree 🟡 Medium graph-valid-tree.ts
269 Graphs Alien Dictionary 🔴 Hard alien-dictionary.ts
435 Intervals Non-overlapping Intervals 🟡 Medium non-overlapping-intervals.ts
252 Intervals Meeting Rooms 🟢 Easy meeting-rooms.ts
253 Intervals Meeting Rooms II 🟡 Medium meeting-rooms-ii.ts
23 Linked List Merge k Sorted Lists 🔴 Hard merge-k-sorted-lists.ts
19 Linked List Remove Nth Node From End of List 🟡 Medium remove-nth-from-end.ts
143 Linked List Reorder List 🟡 Medium reorder-list.ts
73 Matrix Set Matrix Zeroes 🟡 Medium set-matrix-zeroes.ts
54 Matrix Spiral Matrix 🟡 Medium spiral-matrix.ts
48 Matrix Rotate Image 🟡 Medium rotate-image.ts
79 Matrix Word Search 🟡 Medium word-search.ts
424 Sliding Window Longest Repeating Character Replacement 🟡 Medium longest-repeating-character-replacement.ts
76 Sliding Window Minimum Window Substring 🔴 Hard minimum-window-substring.ts
5 Strings Longest Palindromic Substring 🟡 Medium longest-palindromic-substring.ts
647 Strings Palindromic Substrings 🟡 Medium palindromic-substrings.ts
271 Strings Encode and Decode Strings 🟡 Medium encode-decode-strings.ts
124 Trees Binary Tree Maximum Path Sum 🔴 Hard binary-tree-max-path-sum.ts
297 Trees Serialize and Deserialize Binary Tree 🔴 Hard serialize-deserialize.ts
572 Trees Subtree of Another Tree 🟢 Easy subtree-of-another-tree.ts
105 Trees Construct Binary Tree from Preorder and Inorder 🟡 Medium construct-from-preorder-inorder.ts
230 Trees Kth Smallest Element in a BST 🟡 Medium kth-smallest-bst.ts
235 Trees Lowest Common Ancestor of a BST 🟡 Medium lca-bst.ts
211 Tries Add and Search Words 🟡 Medium add-and-search-word.ts
212 Tries Word Search II 🔴 Hard word-search-ii.ts
295 Heap Find Median from Data Stream 🔴 Hard find-median-data-stream.ts

Total solved: 82

Blind 75 complete — the full Blind 75 list is covered in TypeScript (plus a few extra warm-up problems), spanning the same core patterns tested by Grind 75 and NeetCode 150.

About

Data Structures & Algorithms solutions in TypeScript, organized by pattern, with Vitest tests.

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors