Skip to content

Coding interview prep

Blind 75 Interview Questions with JavaScript Solutions

Study the complete Blind 75 list used for coding interview prep. Each problem includes a clear prompt, approach explanation, interview-ready JavaScript solution, and time/space complexity so you can learn patterns—not just memorize code.

This guide covers 75 problems across 17 topic groups (19 easy, 49 medium, 7 hard). Use the table of contents to jump by pattern, then practice explaining each solution out loud before you move on.

What is Blind 75?

Blind 75 is a focused data structures and algorithms checklist for software engineering interviews. Instead of grinding hundreds of random problems, you practice a high-signal set that maps to the patterns interviewers ask most often: hash maps, two pointers, sliding windows, binary search, trees, graphs, heaps, backtracking, and dynamic programming.

On PHPKINGDOM, every Blind 75 problem is written for interview use: short problem statements, intuition-first explanations, and JavaScript solutions you can adapt in a live coding round. Pair this page with our technology coding tracks and theory interview guides for a full prep plan.

How to study Blind 75 effectively

  1. Learn one pattern at a time. Finish a category before hopping around so the technique sticks.
  2. Solve before you peek. Attempt the prompt under a timer, then compare your approach with the explanation and solution.
  3. Write complexity out loud. Interviewers care as much about time/space reasoning as about getting an accepted answer.
  4. Revisit hard problems. Re-solve Medium and Hard items from memory a few days later.
  5. Connect patterns to stories. Be ready to explain when you would choose hashing vs sorting, BFS vs DFS, or greedy vs DP.

Problems

75

Categories

17

Easy / Medium

19 / 49

Hard

7

Full list

All 75 Blind 75 problems with answers

Each problem includes the prompt, approach explanation, JavaScript solution, and complexity. Use the copy button on code blocks to practice rewriting solutions.

Blind 75 category

Arrays & Hashing interview questions

8 Blind 75 problems in arrays & hashing.

Back to contents

1. Contains Duplicate

Easy

Problem statement

Given an integer array nums, return true if any value appears at least twice, and false if every element is distinct.

Approach and explanation

Use a Set while scanning. If a number is already in the Set, a duplicate exists. This is O(n) time and O(n) space and is the expected interview answer versus sorting.

Time complexity: O(n) Space complexity: O(n) Category: Arrays & Hashing

JavaScript solution

function containsDuplicate(nums) {
  const seen = new Set();
  for (const n of nums) {
    if (seen.has(n)) return true;
    seen.add(n);
  }
  return false;
}

2. Valid Anagram

Easy

Problem statement

Given two strings s and t, return true if t is an anagram of s, and false otherwise. An anagram uses the same characters with the same frequencies.

Approach and explanation

Count character frequencies for s, then decrement for t. If counts go negative or lengths differ, it is not an anagram. Sorting both strings also works but is slower.

Time complexity: O(n) Space complexity: O(1) alphabet Category: Arrays & Hashing

JavaScript solution

function isAnagram(s, t) {
  if (s.length !== t.length) return false;
  const count = {};
  for (const ch of s) count[ch] = (count[ch] || 0) + 1;
  for (const ch of t) {
    if (!count[ch]) return false;
    count[ch]--;
  }
  return true;
}

3. Two Sum

Easy

Problem statement

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. Assume exactly one solution and you may not use the same element twice.

Approach and explanation

Scan once while storing value→index in a map. For each number x, check if target-x was seen. This avoids the O(n²) nested loop.

Time complexity: O(n) Space complexity: O(n) Category: Arrays & Hashing

JavaScript solution

function twoSum(nums, target) {
  const map = new Map();
  for (let i = 0; i < nums.length; i++) {
    const need = target - nums[i];
    if (map.has(need)) return [map.get(need), i];
    map.set(nums[i], i);
  }
  return [];
}

4. Group Anagrams

Medium

Problem statement

Given an array of strings strs, group the anagrams together. Return the groups in any order.

Approach and explanation

Anagrams share the same sorted character signature (or a frequency tuple). Hash by that key and append original words to buckets.

Time complexity: O(n k log k) Space complexity: O(n k) Category: Arrays & Hashing

JavaScript solution

function groupAnagrams(strs) {
  const map = new Map();
  for (const s of strs) {
    const key = s.split('').sort().join('');
    if (!map.has(key)) map.set(key, []);
    map.get(key).push(s);
  }
  return [...map.values()];
}

5. Top K Frequent Elements

Medium

Problem statement

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Approach and explanation

Count frequencies, then use bucket sort: index = frequency, values = numbers with that count. Collect from high frequency down until you have k elements. Avoids a full sort.

Time complexity: O(n) Space complexity: O(n) Category: Arrays & Hashing

JavaScript solution

function topKFrequent(nums, k) {
  const freq = new Map();
  for (const n of nums) freq.set(n, (freq.get(n) || 0) + 1);
  const buckets = Array.from({ length: nums.length + 1 }, () => []);
  for (const [n, c] of freq) buckets[c].push(n);
  const res = [];
  for (let i = buckets.length - 1; i >= 0 && res.length < k; i--) {
    for (const n of buckets[i]) {
      res.push(n);
      if (res.length === k) return res;
    }
  }
  return res;
}

6. Product of Array Except Self

Medium

Problem statement

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all elements of nums except nums[i]. Solve without division and in O(n).

Approach and explanation

First pass build prefix products into the result. Second pass multiply by a running suffix product. This yields left*right for each index without division.

Time complexity: O(n) Space complexity: O(1) extra Category: Arrays & Hashing

JavaScript solution

function productExceptSelf(nums) {
  const n = nums.length;
  const out = Array(n).fill(1);
  let prefix = 1;
  for (let i = 0; i < n; i++) {
    out[i] = prefix;
    prefix *= nums[i];
  }
  let suffix = 1;
  for (let i = n - 1; i >= 0; i--) {
    out[i] *= suffix;
    suffix *= nums[i];
  }
  return out;
}

7. Encode and Decode Strings

Medium

Problem statement

Design an algorithm to encode a list of strings to a single string, then decode that string back to the original list. Strings may contain any UTF-8 characters.

Approach and explanation

A common safe scheme is length#string for each word. When decoding, read the integer length until #, then take that many characters. Delimiters alone fail if strings can contain them.

Time complexity: O(n) Space complexity: O(n) Category: Arrays & Hashing

JavaScript solution

function encode(strs) {
  return strs.map((s) => s.length + '#' + s).join('');
}

function decode(s) {
  const res = [];
  let i = 0;
  while (i < s.length) {
    let j = i;
    while (s[j] !== '#') j++;
    const len = Number(s.slice(i, j));
    res.push(s.slice(j + 1, j + 1 + len));
    i = j + 1 + len;
  }
  return res;
}

8. Longest Consecutive Sequence

Medium

Problem statement

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. Must run in O(n) time.

Approach and explanation

Put numbers in a Set. Only start counting from numbers that have no left neighbor (n-1 missing). Extend rightward until the streak breaks. Each number is visited a constant number of times.

Time complexity: O(n) Space complexity: O(n) Category: Arrays & Hashing

JavaScript solution

function longestConsecutive(nums) {
  const set = new Set(nums);
  let best = 0;
  for (const n of set) {
    if (set.has(n - 1)) continue;
    let len = 1;
    while (set.has(n + len)) len++;
    best = Math.max(best, len);
  }
  return best;
}

Blind 75 category

Two Pointers interview questions

3 Blind 75 problems in two pointers.

Back to contents

9. Valid Palindrome

Easy

Problem statement

Given a string s, return true if it is a palindrome after converting to lowercase and removing all non-alphanumeric characters.

Approach and explanation

Two pointers from both ends skip non-alphanumeric characters and compare lowercased characters. If any mismatch occurs it is not a palindrome.

Time complexity: O(n) Space complexity: O(1) Category: Two Pointers

JavaScript solution

function isPalindrome(s) {
  let l = 0, r = s.length - 1;
  while (l < r) {
    while (l < r && !/[a-z0-9]/i.test(s[l])) l++;
    while (l < r && !/[a-z0-9]/i.test(s[r])) r--;
    if (s[l].toLowerCase() !== s[r].toLowerCase()) return false;
    l++; r--;
  }
  return true;
}

10. 3Sum

Medium

Problem statement

Given an integer array nums, return all unique triplets [nums[i], nums[j], nums[k]] such that i, j, k are distinct and the sum is zero.

Approach and explanation

Sort, then fix one index i and two-pointer the rest for target -nums[i]. Skip duplicates for i/l/r to avoid repeated triplets.

Time complexity: O(n²) Space complexity: O(1) extra Category: Two Pointers

JavaScript solution

function threeSum(nums) {
  nums.sort((a, b) => a - b);
  const res = [];
  for (let i = 0; i < nums.length; i++) {
    if (i > 0 && nums[i] === nums[i - 1]) continue;
    let l = i + 1, r = nums.length - 1;
    while (l < r) {
      const sum = nums[i] + nums[l] + nums[r];
      if (sum === 0) {
        res.push([nums[i], nums[l], nums[r]]);
        l++; r--;
        while (l < r && nums[l] === nums[l - 1]) l++;
        while (l < r && nums[r] === nums[r + 1]) r--;
      } else if (sum < 0) l++;
      else r--;
    }
  }
  return res;
}

11. Container With Most Water

Medium

Problem statement

You are given height[i] as vertical lines. Choose two lines that with the x-axis form a container holding the most water. Return the max area.

Approach and explanation

Start with widest container (left=0, right=n-1). Area is min(height[l], height[r]) * width. Move the shorter pointer inward because width shrinks—only a taller line can improve area.

Time complexity: O(n) Space complexity: O(1) Category: Two Pointers

JavaScript solution

function maxArea(height) {
  let l = 0, r = height.length - 1, best = 0;
  while (l < r) {
    best = Math.max(best, Math.min(height[l], height[r]) * (r - l));
    if (height[l] < height[r]) l++;
    else r--;
  }
  return best;
}

Blind 75 category

Sliding Window interview questions

4 Blind 75 problems in sliding window.

Back to contents

12. Best Time to Buy and Sell Stock

Easy

Problem statement

You are given prices[i] as the stock price on day i. Choose one day to buy and a later day to sell to maximize profit. Return max profit or 0.

Approach and explanation

Track the minimum price seen so far. At each day, candidate profit is price - minSoFar. Update the answer. This is a one-pass sliding minimum window.

Time complexity: O(n) Space complexity: O(1) Category: Sliding Window

JavaScript solution

function maxProfit(prices) {
  let minPrice = Infinity, best = 0;
  for (const p of prices) {
    minPrice = Math.min(minPrice, p);
    best = Math.max(best, p - minPrice);
  }
  return best;
}

13. Longest Substring Without Repeating Characters

Medium

Problem statement

Given a string s, find the length of the longest substring without repeating characters.

Approach and explanation

Maintain a window [left, right] with unique chars using a map of last indices. When a duplicate enters, move left past its previous index. Track max window length.

Time complexity: O(n) Space complexity: O(min(n, alphabet)) Category: Sliding Window

JavaScript solution

function lengthOfLongestSubstring(s) {
  const last = new Map();
  let left = 0, best = 0;
  for (let right = 0; right < s.length; right++) {
    if (last.has(s[right]) && last.get(s[right]) >= left) {
      left = last.get(s[right]) + 1;
    }
    last.set(s[right], right);
    best = Math.max(best, right - left + 1);
  }
  return best;
}

14. Longest Repeating Character Replacement

Medium

Problem statement

You can replace any character in a string s with another uppercase letter at most k times. Return the length of the longest substring containing the same letter after replacements.

Approach and explanation

Sliding window where (windowLength - maxFreqInWindow) is replacements needed. If that exceeds k, shrink from the left. Max frequency in window can be tracked as you expand.

Time complexity: O(n) Space complexity: O(1) Category: Sliding Window

JavaScript solution

function characterReplacement(s, k) {
  const count = {};
  let left = 0, maxFreq = 0, best = 0;
  for (let right = 0; right < s.length; right++) {
    count[s[right]] = (count[s[right]] || 0) + 1;
    maxFreq = Math.max(maxFreq, count[s[right]]);
    while (right - left + 1 - maxFreq > k) {
      count[s[left]]--;
      left++;
    }
    best = Math.max(best, right - left + 1);
  }
  return best;
}

15. Minimum Window Substring

Hard

Problem statement

Given strings s and t, return the minimum window substring of s such that every character in t (including duplicates) is included. If none exists, return "".

Approach and explanation

Use need counts for t and a sliding window that expands until all required characters are covered (have === needTypes). Then shrink from the left to minimize while still valid.

Time complexity: O(|s| + |t|) Space complexity: O(1) alphabet Category: Sliding Window

JavaScript solution

function minWindow(s, t) {
  if (!t) return '';
  const need = {};
  for (const ch of t) need[ch] = (need[ch] || 0) + 1;
  let needTypes = Object.keys(need).length;
  let have = 0, left = 0;
  const window = {};
  let ans = [-1, -1], ansLen = Infinity;
  for (let right = 0; right < s.length; right++) {
    const c = s[right];
    window[c] = (window[c] || 0) + 1;
    if (need[c] && window[c] === need[c]) have++;
    while (have === needTypes) {
      if (right - left + 1 < ansLen) {
        ans = [left, right];
        ansLen = right - left + 1;
      }
      window[s[left]]--;
      if (need[s[left]] && window[s[left]] < need[s[left]]) have--;
      left++;
    }
  }
  return ansLen === Infinity ? '' : s.slice(ans[0], ans[1] + 1);
}

Blind 75 category

Stack interview questions

1 Blind 75 problems in stack.

Back to contents

16. Valid Parentheses

Easy

Problem statement

Given a string s containing just the characters (), {}, and [], determine if the input string is valid. Brackets must close in the correct order.

Approach and explanation

Push opening brackets onto a stack. On a closing bracket, the stack top must be the matching opener. At the end the stack must be empty.

Time complexity: O(n) Space complexity: O(n) Category: Stack

JavaScript solution

function isValid(s) {
  const stack = [];
  const map = { ')': '(', ']': '[', '}': '{' };
  for (const ch of s) {
    if (ch === '(' || ch === '[' || ch === '{') stack.push(ch);
    else {
      if (stack.pop() !== map[ch]) return false;
    }
  }
  return stack.length === 0;
}

Blind 75 category

Linked List interview questions

6 Blind 75 problems in linked list.

Back to contents

19. Reverse Linked List

Easy

Problem statement

Given the head of a singly linked list, reverse the list and return the new head. ListNode: { val, next }.

Approach and explanation

Iterate with prev/curr. Point curr.next to prev, then advance. At the end prev is the new head. Recursion also works but uses stack space.

Time complexity: O(n) Space complexity: O(1) Category: Linked List

JavaScript solution

function reverseList(head) {
  let prev = null, curr = head;
  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  return prev;
}

20. Merge Two Sorted Lists

Easy

Problem statement

You are given the heads of two sorted linked lists. Merge them into one sorted list and return its head.

Approach and explanation

Use a dummy node and always attach the smaller current node from list1/list2. Append any remainder when one list ends.

Time complexity: O(n + m) Space complexity: O(1) Category: Linked List

JavaScript solution

function mergeTwoLists(list1, list2) {
  const dummy = { val: 0, next: null };
  let cur = dummy;
  while (list1 && list2) {
    if (list1.val <= list2.val) {
      cur.next = list1;
      list1 = list1.next;
    } else {
      cur.next = list2;
      list2 = list2.next;
    }
    cur = cur.next;
  }
  cur.next = list1 || list2;
  return dummy.next;
}

21. Reorder List

Medium

Problem statement

Reorder list L0→L1→…→Ln-1→Ln into L0→Ln→L1→Ln-1→…. Do it in-place.

Approach and explanation

Find middle with slow/fast, reverse the second half, then weave the two halves together node by node.

Time complexity: O(n) Space complexity: O(1) Category: Linked List

JavaScript solution

function reorderList(head) {
  if (!head || !head.next) return;
  let slow = head, fast = head;
  while (fast.next && fast.next.next) {
    slow = slow.next;
    fast = fast.next.next;
  }
  let prev = null, curr = slow.next;
  slow.next = null;
  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  let a = head, b = prev;
  while (b) {
    const an = a.next, bn = b.next;
    a.next = b;
    b.next = an;
    a = an;
    b = bn;
  }
}

22. Remove Nth Node From End of List

Medium

Problem statement

Given the head of a linked list, remove the nth node from the end and return its head.

Approach and explanation

Advance a fast pointer n steps, then move slow and fast together. When fast ends, slow is before the node to delete. A dummy handles deleting the head.

Time complexity: O(n) Space complexity: O(1) Category: Linked List

JavaScript solution

function removeNthFromEnd(head, n) {
  const dummy = { val: 0, next: head };
  let fast = dummy, slow = dummy;
  for (let i = 0; i < n; i++) fast = fast.next;
  while (fast.next) {
    fast = fast.next;
    slow = slow.next;
  }
  slow.next = slow.next.next;
  return dummy.next;
}

23. Linked List Cycle

Easy

Problem statement

Given head, return true if there is a cycle in the linked list.

Approach and explanation

Floyd’s tortoise and hare: slow moves one step, fast two. If they meet, a cycle exists. If fast hits null, no cycle.

Time complexity: O(n) Space complexity: O(1) Category: Linked List

JavaScript solution

function hasCycle(head) {
  let slow = head, fast = head;
  while (fast && fast.next) {
    slow = slow.next;
    fast = fast.next.next;
    if (slow === fast) return true;
  }
  return false;
}

24. Merge K Sorted Lists

Hard

Problem statement

You are given an array of k linked-lists, each sorted in ascending order. Merge all into one sorted linked list.

Approach and explanation

Pairwise merge (divide and conquer) repeatedly merges lists until one remains. Min-heap of heads also works in O(N log k).

Time complexity: O(N log k) Space complexity: O(1) extra Category: Linked List

JavaScript solution

function mergeTwo(a, b) {
  const dummy = { val: 0, next: null };
  let cur = dummy;
  while (a && b) {
    if (a.val <= b.val) { cur.next = a; a = a.next; }
    else { cur.next = b; b = b.next; }
    cur = cur.next;
  }
  cur.next = a || b;
  return dummy.next;
}

function mergeKLists(lists) {
  if (!lists.length) return null;
  while (lists.length > 1) {
    const merged = [];
    for (let i = 0; i < lists.length; i += 2) {
      merged.push(mergeTwo(lists[i], lists[i + 1] || null));
    }
    lists = merged;
  }
  return lists[0];
}

Blind 75 category

Trees interview questions

11 Blind 75 problems in trees.

Back to contents

25. Invert Binary Tree

Easy

Problem statement

Given the root of a binary tree, invert the tree (swap every left and right child) and return its root.

Approach and explanation

Recursively swap left and right subtrees for every node. BFS/DFS iteration works the same way.

Time complexity: O(n) Space complexity: O(h) Category: Trees

JavaScript solution

function invertTree(root) {
  if (!root) return null;
  const tmp = root.left;
  root.left = invertTree(root.right);
  root.right = invertTree(tmp);
  return root;
}

26. Maximum Depth of Binary Tree

Easy

Problem statement

Given the root of a binary tree, return its maximum depth (number of nodes along the longest root-to-leaf path).

Approach and explanation

Depth is 1 + max(depth(left), depth(right)). Empty tree has depth 0.

Time complexity: O(n) Space complexity: O(h) Category: Trees

JavaScript solution

function maxDepth(root) {
  if (!root) return 0;
  return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}

27. Same Tree

Easy

Problem statement

Given roots of two binary trees p and q, write a function to check whether they are the same (identical structure and values).

Approach and explanation

Both null means equal. One null means not. Otherwise values must match and left/right subtrees must recursively match.

Time complexity: O(n) Space complexity: O(h) Category: Trees

JavaScript solution

function isSameTree(p, q) {
  if (!p && !q) return true;
  if (!p || !q || p.val !== q.val) return false;
  return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}

28. Subtree of Another Tree

Easy

Problem statement

Given roots of two binary trees root and subRoot, return true if root has a subtree with the same structure and node values as subRoot.

Approach and explanation

For every node in root, check isSameTree against subRoot. Or serialize both trees and check substring with careful encoding.

Time complexity: O(n m) Space complexity: O(h) Category: Trees

JavaScript solution

function isSameTree(p, q) {
  if (!p && !q) return true;
  if (!p || !q || p.val !== q.val) return false;
  return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}

function isSubtree(root, subRoot) {
  if (!subRoot) return true;
  if (!root) return false;
  if (isSameTree(root, subRoot)) return true;
  return isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot);
}

29. Lowest Common Ancestor of a Binary Search Tree

Medium

Problem statement

Given a BST and nodes p and q, find their lowest common ancestor. Both nodes exist in the tree.

Approach and explanation

In a BST, if both values are less than root, LCA is left; both greater → right; otherwise root splits them and is the LCA.

Time complexity: O(h) Space complexity: O(1) Category: Trees

JavaScript solution

function lowestCommonAncestor(root, p, q) {
  let cur = root;
  while (cur) {
    if (p.val < cur.val && q.val < cur.val) cur = cur.left;
    else if (p.val > cur.val && q.val > cur.val) cur = cur.right;
    else return cur;
  }
  return null;
}

30. Binary Tree Level Order Traversal

Medium

Problem statement

Given the root of a binary tree, return the level order traversal of its nodes’ values (left to right, level by level).

Approach and explanation

BFS with a queue. Process the queue size for each level, pushing children for the next level.

Time complexity: O(n) Space complexity: O(n) Category: Trees

JavaScript solution

function levelOrder(root) {
  if (!root) return [];
  const res = [], q = [root];
  while (q.length) {
    const size = q.length, level = [];
    for (let i = 0; i < size; i++) {
      const node = q.shift();
      level.push(node.val);
      if (node.left) q.push(node.left);
      if (node.right) q.push(node.right);
    }
    res.push(level);
  }
  return res;
}

31. Validate Binary Search Tree

Medium

Problem statement

Given the root of a binary tree, determine if it is a valid binary search tree.

Approach and explanation

Pass (min, max) bounds down the tree. Each node value must be strictly inside the open interval from its ancestors.

Time complexity: O(n) Space complexity: O(h) Category: Trees

JavaScript solution

function isValidBST(root) {
  function dfs(node, low, high) {
    if (!node) return true;
    if (node.val <= low || node.val >= high) return false;
    return dfs(node.left, low, node.val) && dfs(node.right, node.val, high);
  }
  return dfs(root, -Infinity, Infinity);
}

32. Kth Smallest Element in a BST

Medium

Problem statement

Given the root of a BST and integer k, return the kth smallest value (1-indexed) among all nodes.

Approach and explanation

Inorder traversal of a BST yields sorted order. Decrement k as you visit; when k hits 0, that node is the answer.

Time complexity: O(h + k) Space complexity: O(h) Category: Trees

JavaScript solution

function kthSmallest(root, k) {
  const stack = [];
  let cur = root;
  while (true) {
    while (cur) {
      stack.push(cur);
      cur = cur.left;
    }
    cur = stack.pop();
    k--;
    if (k === 0) return cur.val;
    cur = cur.right;
  }
}

33. Construct Binary Tree from Preorder and Inorder Traversal

Medium

Problem statement

Given two integer arrays preorder and inorder representing a tree’s traversals, construct and return the binary tree. Values are unique.

Approach and explanation

Preorder[0] is root. Find it in inorder to split left/right sizes. Recursively build left then right subtrees, advancing a preorder index.

Time complexity: O(n) Space complexity: O(n) Category: Trees

JavaScript solution

function buildTree(preorder, inorder) {
  const idx = new Map(inorder.map((v, i) => [v, i]));
  let p = 0;
  function build(l, r) {
    if (l > r) return null;
    const root = { val: preorder[p++], left: null, right: null };
    const mid = idx.get(root.val);
    root.left = build(l, mid - 1);
    root.right = build(mid + 1, r);
    return root;
  }
  return build(0, inorder.length - 1);
}

34. Binary Tree Maximum Path Sum

Hard

Problem statement

A path is any node sequence where each pair of adjacent nodes has an edge. Paths need not pass through the root. Return the maximum path sum.

Approach and explanation

For each node, compute max gain contributed upward as node.val + max(0, leftGain, rightGain). Update global answer with node.val + leftGain + rightGain (path through node).

Time complexity: O(n) Space complexity: O(h) Category: Trees

JavaScript solution

function maxPathSum(root) {
  let best = -Infinity;
  function gain(node) {
    if (!node) return 0;
    const left = Math.max(0, gain(node.left));
    const right = Math.max(0, gain(node.right));
    best = Math.max(best, node.val + left + right);
    return node.val + Math.max(left, right);
  }
  gain(root);
  return best;
}

35. Serialize and Deserialize Binary Tree

Hard

Problem statement

Design algorithms to serialize a binary tree to a string and deserialize that string back to the same tree structure.

Approach and explanation

BFS/preorder with null markers works. Encode nulls explicitly so structure is recoverable. Split on deserialize and rebuild recursively or with a queue.

Time complexity: O(n) Space complexity: O(n) Category: Trees

JavaScript solution

function serialize(root) {
  const out = [];
  function dfs(node) {
    if (!node) { out.push('N'); return; }
    out.push(String(node.val));
    dfs(node.left);
    dfs(node.right);
  }
  dfs(root);
  return out.join(',');
}

function deserialize(data) {
  const vals = data.split(',');
  let i = 0;
  function dfs() {
    if (vals[i] === 'N') { i++; return null; }
    const node = { val: Number(vals[i++]), left: null, right: null };
    node.left = dfs();
    node.right = dfs();
    return node;
  }
  return dfs();
}

Blind 75 category

Tries interview questions

3 Blind 75 problems in tries.

Back to contents

36. Implement Trie (Prefix Tree)

Medium

Problem statement

Implement a trie with insert, search (exact word), and startsWith (prefix) operations.

Approach and explanation

Each node holds a map of children and an end-of-word flag. Insert walks/creates nodes; search requires end flag; startsWith only needs the path to exist.

Time complexity: O(L) per op Space complexity: O(total chars) Category: Tries

JavaScript solution

class TrieNode {
  constructor() {
    this.children = {};
    this.end = false;
  }
}

class Trie {
  constructor() { this.root = new TrieNode(); }
  insert(word) {
    let node = this.root;
    for (const ch of word) {
      if (!node.children[ch]) node.children[ch] = new TrieNode();
      node = node.children[ch];
    }
    node.end = true;
  }
  search(word) {
    let node = this.root;
    for (const ch of word) {
      if (!node.children[ch]) return false;
      node = node.children[ch];
    }
    return node.end;
  }
  startsWith(prefix) {
    let node = this.root;
    for (const ch of prefix) {
      if (!node.children[ch]) return false;
      node = node.children[ch];
    }
    return true;
  }
}

37. Design Add and Search Words Data Structure

Medium

Problem statement

Design a data structure that supports adding words and searching words where "." can match any letter.

Approach and explanation

Store words in a trie. On ".", branch DFS into every child. Exact characters follow the single child path.

Time complexity: O(26^L) worst search Space complexity: O(total chars) Category: Tries

JavaScript solution

class WordDictionary {
  constructor() { this.root = {}; }
  addWord(word) {
    let node = this.root;
    for (const ch of word) {
      if (!node[ch]) node[ch] = {};
      node = node[ch];
    }
    node.end = true;
  }
  search(word) {
    const dfs = (i, node) => {
      if (i === word.length) return !!node.end;
      const ch = word[i];
      if (ch === '.') {
        for (const key of Object.keys(node)) {
          if (key !== 'end' && dfs(i + 1, node[key])) return true;
        }
        return false;
      }
      if (!node[ch]) return false;
      return dfs(i + 1, node[ch]);
    };
    return dfs(0, this.root);
  }
}

38. Word Search II

Hard

Problem statement

Given an m x n board of characters and a list of strings words, return all words on the board. Words can be constructed from adjacent cells (no reuse in one word).

Approach and explanation

Build a trie of words, then DFS from each cell while walking the trie. Mark visited cells, collect when an end node is reached, and prune completed words for speed.

Time complexity: O(m n 4^L) Space complexity: O(total chars) Category: Tries

JavaScript solution

function findWords(board, words) {
  const root = {};
  for (const w of words) {
    let node = root;
    for (const ch of w) {
      if (!node[ch]) node[ch] = {};
      node = node[ch];
    }
    node.word = w;
  }
  const res = [];
  const rows = board.length, cols = board[0].length;
  function dfs(r, c, node) {
    if (r < 0 || c < 0 || r >= rows || c >= cols) return;
    const ch = board[r][c];
    if (!node[ch]) return;
    const next = node[ch];
    if (next.word) {
      res.push(next.word);
      next.word = null;
    }
    board[r][c] = '#';
    dfs(r + 1, c, next);
    dfs(r - 1, c, next);
    dfs(r, c + 1, next);
    dfs(r, c - 1, next);
    board[r][c] = ch;
  }
  for (let r = 0; r < rows; r++) {
    for (let c = 0; c < cols; c++) dfs(r, c, root);
  }
  return res;
}

Blind 75 category

Heap / Priority Queue interview questions

1 Blind 75 problems in heap / priority queue.

Back to contents

39. Find Median from Data Stream

Hard

Problem statement

Design a data structure that supports adding integers from a stream and finding the median of all elements so far.

Approach and explanation

Maintain a max-heap for the lower half and a min-heap for the upper half, balanced so sizes differ by at most 1. Median is top of larger heap or average of both tops. Here heaps are simulated with sorted arrays for portability.

Time complexity: O(n) add (array sim) Space complexity: O(n) Category: Heap / Priority Queue

JavaScript solution

class MedianFinder {
  constructor() {
    this.low = []; // max-heap via sorted asc, median at end
    this.high = []; // min-heap via sorted asc, median at start
  }
  addNum(num) {
    // insert into low (keep sorted)
    let i = this.low.findIndex((x) => x > num);
    if (i === -1) this.low.push(num);
    else this.low.splice(i, 0, num);
    // move max of low to high
    this.high.unshift(this.low.pop());
    this.high.sort((a, b) => a - b);
    if (this.high.length > this.low.length) {
      this.low.push(this.high.shift());
    }
  }
  findMedian() {
    if (this.low.length > this.high.length) return this.low[this.low.length - 1];
    return (this.low[this.low.length - 1] + this.high[0]) / 2;
  }
}

Blind 75 category

Backtracking interview questions

2 Blind 75 problems in backtracking.

Back to contents

40. Combination Sum

Medium

Problem statement

Given distinct candidates and a target, return all unique combinations where chosen numbers sum to target. The same number may be chosen unlimited times.

Approach and explanation

Backtrack from an index, either reuse candidates[i] (stay at i) or skip to i+1. Prune when sum exceeds target. Sorting helps pruning.

Time complexity: O(2^{t/min}) Space complexity: O(target/min) Category: Backtracking

JavaScript solution

function combinationSum(candidates, target) {
  candidates.sort((a, b) => a - b);
  const res = [];
  function dfs(start, remain, path) {
    if (remain === 0) { res.push([...path]); return; }
    for (let i = start; i < candidates.length; i++) {
      if (candidates[i] > remain) break;
      path.push(candidates[i]);
      dfs(i, remain - candidates[i], path);
      path.pop();
    }
  }
  dfs(0, target, []);
  return res;
}

Blind 75 category

Graphs interview questions

7 Blind 75 problems in graphs.

Back to contents

42. Number of Islands

Medium

Problem statement

Given an m x n 2D binary grid, return the number of islands. An island is "1"s connected 4-directionally and surrounded by water "0".

Approach and explanation

Scan the grid. On land, increment count and DFS/BFS flood-fill that island to water so it is not recounted.

Time complexity: O(m n) Space complexity: O(m n) Category: Graphs

JavaScript solution

function numIslands(grid) {
  if (!grid.length) return 0;
  const rows = grid.length, cols = grid[0].length;
  let count = 0;
  function dfs(r, c) {
    if (r < 0 || c < 0 || r >= rows || c >= cols || grid[r][c] !== '1') return;
    grid[r][c] = '0';
    dfs(r + 1, c); dfs(r - 1, c); dfs(r, c + 1); dfs(r, c - 1);
  }
  for (let r = 0; r < rows; r++) {
    for (let c = 0; c < cols; c++) {
      if (grid[r][c] === '1') { count++; dfs(r, c); }
    }
  }
  return count;
}

43. Clone Graph

Medium

Problem statement

Given a reference of a node in a connected undirected graph, return a deep copy of the graph. Each node has val and neighbors list.

Approach and explanation

DFS/BFS with a map from original node to clone. Create the clone when first seen, then recursively clone neighbors and wire edges.

Time complexity: O(V + E) Space complexity: O(V) Category: Graphs

JavaScript solution

function cloneGraph(node) {
  if (!node) return null;
  const map = new Map();
  function dfs(n) {
    if (map.has(n)) return map.get(n);
    const copy = { val: n.val, neighbors: [] };
    map.set(n, copy);
    for (const nei of n.neighbors) copy.neighbors.push(dfs(nei));
    return copy;
  }
  return dfs(node);
}

44. Pacific Atlantic Water Flow

Medium

Problem statement

Given heights matrix, return coordinates from which water can flow to both Pacific (top/left) and Atlantic (bottom/right). Flow only to equal/lower neighbors.

Approach and explanation

Reverse the thinking: DFS/BFS inland from Pacific shores and Atlantic shores following non-decreasing heights. Cells reachable from both oceans are answers.

Time complexity: O(m n) Space complexity: O(m n) Category: Graphs

JavaScript solution

function pacificAtlantic(heights) {
  const rows = heights.length, cols = heights[0].length;
  const pac = Array.from({ length: rows }, () => Array(cols).fill(false));
  const atl = Array.from({ length: rows }, () => Array(cols).fill(false));
  function dfs(r, c, seen, prev) {
    if (r < 0 || c < 0 || r >= rows || c >= cols || seen[r][c] || heights[r][c] < prev) return;
    seen[r][c] = true;
    const h = heights[r][c];
    dfs(r + 1, c, seen, h); dfs(r - 1, c, seen, h);
    dfs(r, c + 1, seen, h); dfs(r, c - 1, seen, h);
  }
  for (let c = 0; c < cols; c++) { dfs(0, c, pac, -1); dfs(rows - 1, c, atl, -1); }
  for (let r = 0; r < rows; r++) { dfs(r, 0, pac, -1); dfs(r, cols - 1, atl, -1); }
  const res = [];
  for (let r = 0; r < rows; r++) {
    for (let c = 0; c < cols; c++) if (pac[r][c] && atl[r][c]) res.push([r, c]);
  }
  return res;
}

45. Course Schedule

Medium

Problem statement

There are numCourses labeled 0 to n-1. prerequisites[i] = [ai, bi] means bi must be taken before ai. Return true if you can finish all courses.

Approach and explanation

Build a directed graph and detect cycles (DFS states: unvisited/visiting/visited) or use Kahn’s topological sort. A cycle means impossible.

Time complexity: O(V + E) Space complexity: O(V + E) Category: Graphs

JavaScript solution

function canFinish(numCourses, prerequisites) {
  const g = Array.from({ length: numCourses }, () => []);
  for (const [a, b] of prerequisites) g[b].push(a);
  const state = Array(numCourses).fill(0); // 0=todo,1=doing,2=done
  function dfs(n) {
    if (state[n] === 1) return false;
    if (state[n] === 2) return true;
    state[n] = 1;
    for (const nei of g[n]) if (!dfs(nei)) return false;
    state[n] = 2;
    return true;
  }
  for (let i = 0; i < numCourses; i++) if (!dfs(i)) return false;
  return true;
}

46. Number of Connected Components in an Undirected Graph

Medium

Problem statement

Given n nodes labeled 0..n-1 and a list of undirected edges, return the number of connected components.

Approach and explanation

Build adjacency lists, then DFS/BFS or Union-Find. Each unvisited node starts a new component.

Time complexity: O(V + E) Space complexity: O(V + E) Category: Graphs

JavaScript solution

function countComponents(n, edges) {
  const g = Array.from({ length: n }, () => []);
  for (const [a, b] of edges) { g[a].push(b); g[b].push(a); }
  const seen = Array(n).fill(false);
  function dfs(u) {
    seen[u] = true;
    for (const v of g[u]) if (!seen[v]) dfs(v);
  }
  let count = 0;
  for (let i = 0; i < n; i++) if (!seen[i]) { count++; dfs(i); }
  return count;
}

47. Graph Valid Tree

Medium

Problem statement

Given n nodes labeled 0..n-1 and a list of undirected edges, return whether these edges make a valid tree.

Approach and explanation

A tree on n nodes has exactly n-1 edges and is connected with no cycles. Check edge count then DFS/Union-Find for connectivity and cycles.

Time complexity: O(V + E) Space complexity: O(V + E) Category: Graphs

JavaScript solution

function validTree(n, edges) {
  if (edges.length !== n - 1) return false;
  const g = Array.from({ length: n }, () => []);
  for (const [a, b] of edges) { g[a].push(b); g[b].push(a); }
  const seen = new Set();
  function dfs(u, parent) {
    if (seen.has(u)) return false;
    seen.add(u);
    for (const v of g[u]) {
      if (v === parent) continue;
      if (!dfs(v, u)) return false;
    }
    return true;
  }
  return dfs(0, -1) && seen.size === n;
}

48. Alien Dictionary

Hard

Problem statement

You are given a list of words sorted lexicographically by alien language rules. Derive a valid order of unique letters. Return "" if invalid.

Approach and explanation

Compare adjacent words to extract precedence edges (first differing chars). Detect invalid prefix cases. Then topological sort; cycle ⇒ invalid.

Time complexity: O(C) Space complexity: O(1) alphabet Category: Graphs

JavaScript solution

function alienOrder(words) {
  const g = new Map();
  const indeg = new Map();
  for (const w of words) for (const ch of w) {
    if (!g.has(ch)) g.set(ch, new Set());
    if (!indeg.has(ch)) indeg.set(ch, 0);
  }
  for (let i = 0; i < words.length - 1; i++) {
    const a = words[i], b = words[i + 1];
    if (a.length > b.length && a.startsWith(b)) return '';
    for (let j = 0; j < Math.min(a.length, b.length); j++) {
      if (a[j] !== b[j]) {
        if (!g.get(a[j]).has(b[j])) {
          g.get(a[j]).add(b[j]);
          indeg.set(b[j], indeg.get(b[j]) + 1);
        }
        break;
      }
    }
  }
  const q = [...indeg.keys()].filter((ch) => indeg.get(ch) === 0);
  let order = '';
  while (q.length) {
    const ch = q.shift();
    order += ch;
    for (const nei of g.get(ch)) {
      indeg.set(nei, indeg.get(nei) - 1);
      if (indeg.get(nei) === 0) q.push(nei);
    }
  }
  return order.length === indeg.size ? order : '';
}

Blind 75 category

1-D Dynamic Programming interview questions

10 Blind 75 problems in 1-d dynamic programming.

Back to contents

49. Climbing Stairs

Easy

Problem statement

You can climb 1 or 2 steps. Given n stairs, return how many distinct ways you can climb to the top.

Approach and explanation

Classic Fibonacci DP: ways(n) = ways(n-1) + ways(n-2). Keep only two previous values for O(1) space.

Time complexity: O(n) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function climbStairs(n) {
  if (n <= 2) return n;
  let a = 1, b = 2;
  for (let i = 3; i <= n; i++) {
    const c = a + b;
    a = b; b = c;
  }
  return b;
}

50. House Robber

Medium

Problem statement

Houses in a line hold nums[i] money. You cannot rob two adjacent houses. Return max amount you can rob.

Approach and explanation

dp[i] = max(dp[i-1], dp[i-2] + nums[i]). Equivalent to tracking rob/skip while iterating.

Time complexity: O(n) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function rob(nums) {
  let prev2 = 0, prev1 = 0;
  for (const x of nums) {
    const cur = Math.max(prev1, prev2 + x);
    prev2 = prev1;
    prev1 = cur;
  }
  return prev1;
}

51. House Robber II

Medium

Problem statement

Same as House Robber but houses are in a circle, so the first and last houses are adjacent.

Approach and explanation

Because first and last conflict, compute linear robber on ranges [0..n-2] and [1..n-1] and take the max. Handle n=1 separately.

Time complexity: O(n) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function robLinear(nums, l, r) {
  let prev2 = 0, prev1 = 0;
  for (let i = l; i <= r; i++) {
    const cur = Math.max(prev1, prev2 + nums[i]);
    prev2 = prev1;
    prev1 = cur;
  }
  return prev1;
}

function rob(nums) {
  const n = nums.length;
  if (n === 1) return nums[0];
  return Math.max(robLinear(nums, 0, n - 2), robLinear(nums, 1, n - 1));
}

52. Longest Palindromic Substring

Medium

Problem statement

Given a string s, return the longest palindromic substring in s.

Approach and explanation

Expand around each center (odd and even length). Track the best start/end. Expand-around-center is simple and O(n²).

Time complexity: O(n²) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function longestPalindrome(s) {
  let start = 0, end = 0;
  function expand(l, r) {
    while (l >= 0 && r < s.length && s[l] === s[r]) { l--; r++; }
    return [l + 1, r - 1];
  }
  for (let i = 0; i < s.length; i++) {
    for (const [l, r] of [expand(i, i), expand(i, i + 1)]) {
      if (r - l > end - start) { start = l; end = r; }
    }
  }
  return s.slice(start, end + 1);
}

53. Palindromic Substrings

Medium

Problem statement

Given a string s, return the number of palindromic substrings in it. Single characters count.

Approach and explanation

Expand around every center and count each valid expansion. Same center idea as longest palindrome.

Time complexity: O(n²) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function countSubstrings(s) {
  let count = 0;
  function expand(l, r) {
    while (l >= 0 && r < s.length && s[l] === s[r]) {
      count++;
      l--; r++;
    }
  }
  for (let i = 0; i < s.length; i++) {
    expand(i, i);
    expand(i, i + 1);
  }
  return count;
}

54. Decode Ways

Medium

Problem statement

A message containing letters A-Z is encoded to numbers using 1→A ... 26→Z. Given a digit string s, return the number of ways to decode it.

Approach and explanation

dp[i] depends on whether s[i-1] forms a valid single digit (1-9) and s[i-2..i-1] forms 10-26. Leading zeros invalidate a branch.

Time complexity: O(n) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function numDecodings(s) {
  if (!s || s[0] === '0') return 0;
  let prev2 = 1, prev1 = 1;
  for (let i = 1; i < s.length; i++) {
    let cur = 0;
    if (s[i] !== '0') cur += prev1;
    const two = Number(s.slice(i - 1, i + 1));
    if (two >= 10 && two <= 26) cur += prev2;
    prev2 = prev1;
    prev1 = cur;
  }
  return prev1;
}

55. Coin Change

Medium

Problem statement

Given coin denominations and amount, return the fewest coins needed to make that amount. Return -1 if impossible. Unlimited each coin.

Approach and explanation

Unbounded knapsack DP: dp[x] = min coins for amount x. For each coin, update dp[c..amount]. Initialize dp[0]=0 and others Infinity.

Time complexity: O(amount * coins) Space complexity: O(amount) Category: 1-D Dynamic Programming

JavaScript solution

function coinChange(coins, amount) {
  const dp = Array(amount + 1).fill(Infinity);
  dp[0] = 0;
  for (let x = 1; x <= amount; x++) {
    for (const c of coins) {
      if (c <= x) dp[x] = Math.min(dp[x], dp[x - c] + 1);
    }
  }
  return dp[amount] === Infinity ? -1 : dp[amount];
}

56. Maximum Product Subarray

Medium

Problem statement

Given an integer array nums, find a contiguous non-empty subarray with the largest product and return that product.

Approach and explanation

Track max and min products ending here because a negative can flip min to max. Reset conceptually around zeros by using current value alone.

Time complexity: O(n) Space complexity: O(1) Category: 1-D Dynamic Programming

JavaScript solution

function maxProduct(nums) {
  let maxEnd = nums[0], minEnd = nums[0], best = nums[0];
  for (let i = 1; i < nums.length; i++) {
    const x = nums[i];
    const candidates = [x, maxEnd * x, minEnd * x];
    maxEnd = Math.max(...candidates);
    minEnd = Math.min(...candidates);
    best = Math.max(best, maxEnd);
  }
  return best;
}

57. Word Break

Medium

Problem statement

Given string s and a dictionary wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

Approach and explanation

dp[i] means s[0..i) can be segmented. For each end i, try word endings that match and check dp[start].

Time complexity: O(n²) Space complexity: O(n) Category: 1-D Dynamic Programming

JavaScript solution

function wordBreak(s, wordDict) {
  const set = new Set(wordDict);
  const dp = Array(s.length + 1).fill(false);
  dp[0] = true;
  for (let i = 1; i <= s.length; i++) {
    for (let j = 0; j < i; j++) {
      if (dp[j] && set.has(s.slice(j, i))) { dp[i] = true; break; }
    }
  }
  return dp[s.length];
}

58. Longest Increasing Subsequence

Medium

Problem statement

Given an integer array nums, return the length of the longest strictly increasing subsequence.

Approach and explanation

Patience sorting: maintain tails array where tails[len-1] is the smallest tail of all increasing subsequences with length len. Binary search placement. O(n log n).

Time complexity: O(n log n) Space complexity: O(n) Category: 1-D Dynamic Programming

JavaScript solution

function lengthOfLIS(nums) {
  const tails = [];
  for (const x of nums) {
    let l = 0, r = tails.length;
    while (l < r) {
      const m = (l + r) >> 1;
      if (tails[m] < x) l = m + 1;
      else r = m;
    }
    tails[l] = x;
  }
  return tails.length;
}

Blind 75 category

2-D Dynamic Programming interview questions

2 Blind 75 problems in 2-d dynamic programming.

Back to contents

59. Unique Paths

Medium

Problem statement

A robot on an m x n grid starts at top-left and can only move right or down. Return number of unique paths to bottom-right.

Approach and explanation

dp[r][c] = dp[r-1][c] + dp[r][c-1] with first row/col = 1. Can compress to 1D row updates.

Time complexity: O(m n) Space complexity: O(n) Category: 2-D Dynamic Programming

JavaScript solution

function uniquePaths(m, n) {
  const dp = Array(n).fill(1);
  for (let r = 1; r < m; r++) {
    for (let c = 1; c < n; c++) dp[c] += dp[c - 1];
  }
  return dp[n - 1];
}

60. Longest Common Subsequence

Medium

Problem statement

Given two strings text1 and text2, return the length of their longest common subsequence. If none, return 0.

Approach and explanation

Classic DP: if chars equal, dp[i][j] = dp[i-1][j-1]+1 else max of skip either char. Subsequence preserves order but not contiguity.

Time complexity: O(m n) Space complexity: O(m n) Category: 2-D Dynamic Programming

JavaScript solution

function longestCommonSubsequence(text1, text2) {
  const m = text1.length, n = text2.length;
  const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
  for (let i = 1; i <= m; i++) {
    for (let j = 1; j <= n; j++) {
      if (text1[i - 1] === text2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
      else dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
  return dp[m][n];
}

Blind 75 category

Greedy interview questions

2 Blind 75 problems in greedy.

Back to contents

61. Maximum Subarray

Medium

Problem statement

Given an integer array nums, find the contiguous subarray with the largest sum and return its sum.

Approach and explanation

Kadane’s algorithm: either extend the previous best ending here or start fresh at the current element. Track global best.

Time complexity: O(n) Space complexity: O(1) Category: Greedy

JavaScript solution

function maxSubArray(nums) {
  let best = nums[0], cur = nums[0];
  for (let i = 1; i < nums.length; i++) {
    cur = Math.max(nums[i], cur + nums[i]);
    best = Math.max(best, cur);
  }
  return best;
}

62. Jump Game

Medium

Problem statement

You start at index 0 of nums where nums[i] is your max jump length from i. Return true if you can reach the last index.

Approach and explanation

Track the farthest reachable index while scanning. If i moves past farthest, fail. If farthest reaches end, success.

Time complexity: O(n) Space complexity: O(1) Category: Greedy

JavaScript solution

function canJump(nums) {
  let farthest = 0;
  for (let i = 0; i < nums.length; i++) {
    if (i > farthest) return false;
    farthest = Math.max(farthest, i + nums[i]);
  }
  return true;
}

Blind 75 category

Intervals interview questions

5 Blind 75 problems in intervals.

Back to contents

63. Insert Interval

Medium

Problem statement

You are given a list of non-overlapping intervals sorted by start, and a newInterval. Insert it and merge if necessary. Return intervals after insertion.

Approach and explanation

Add all intervals ending before new starts, merge overlaps with new, then append the rest.

Time complexity: O(n) Space complexity: O(n) Category: Intervals

JavaScript solution

function insert(intervals, newInterval) {
  const res = [];
  let i = 0, n = intervals.length;
  while (i < n && intervals[i][1] < newInterval[0]) res.push(intervals[i++]);
  while (i < n && intervals[i][0] <= newInterval[1]) {
    newInterval[0] = Math.min(newInterval[0], intervals[i][0]);
    newInterval[1] = Math.max(newInterval[1], intervals[i][1]);
    i++;
  }
  res.push(newInterval);
  while (i < n) res.push(intervals[i++]);
  return res;
}

64. Merge Intervals

Medium

Problem statement

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals.

Approach and explanation

Sort by start. If current starts before or at last merged end, extend the end; otherwise push a new interval.

Time complexity: O(n log n) Space complexity: O(n) Category: Intervals

JavaScript solution

function merge(intervals) {
  intervals.sort((a, b) => a[0] - b[0]);
  const res = [intervals[0].slice()];
  for (let i = 1; i < intervals.length; i++) {
    const last = res[res.length - 1];
    if (intervals[i][0] <= last[1]) last[1] = Math.max(last[1], intervals[i][1]);
    else res.push(intervals[i].slice());
  }
  return res;
}

65. Non-overlapping Intervals

Medium

Problem statement

Given intervals, return the minimum number of intervals to remove to make the rest non-overlapping.

Approach and explanation

Sort by end time. Greedily keep intervals that start after the last kept end. Removals = total - kept.

Time complexity: O(n log n) Space complexity: O(1) Category: Intervals

JavaScript solution

function eraseOverlapIntervals(intervals) {
  intervals.sort((a, b) => a[1] - b[1]);
  let kept = 0, end = -Infinity;
  for (const [s, e] of intervals) {
    if (s >= end) { kept++; end = e; }
  }
  return intervals.length - kept;
}

66. Meeting Rooms

Easy

Problem statement

Given an array of meeting time intervals consisting of start and end times, determine if a person could attend all meetings.

Approach and explanation

Sort by start. If any meeting starts before the previous one ends, there is a conflict.

Time complexity: O(n log n) Space complexity: O(1) Category: Intervals

JavaScript solution

function canAttendMeetings(intervals) {
  intervals.sort((a, b) => a[0] - b[0]);
  for (let i = 1; i < intervals.length; i++) {
    if (intervals[i][0] < intervals[i - 1][1]) return false;
  }
  return true;
}

67. Meeting Rooms II

Medium

Problem statement

Given an array of meeting time intervals, find the minimum number of conference rooms required.

Approach and explanation

Sort starts and ends. Sweep: when a meeting starts before earliest end, need another room; otherwise free a room by advancing end pointer.

Time complexity: O(n log n) Space complexity: O(n) Category: Intervals

JavaScript solution

function minMeetingRooms(intervals) {
  const starts = intervals.map((x) => x[0]).sort((a, b) => a - b);
  const ends = intervals.map((x) => x[1]).sort((a, b) => a - b);
  let rooms = 0, endPtr = 0;
  for (let i = 0; i < starts.length; i++) {
    if (starts[i] < ends[endPtr]) rooms++;
    else endPtr++;
  }
  return rooms;
}

Blind 75 category

Math & Geometry interview questions

3 Blind 75 problems in math & geometry.

Back to contents

68. Rotate Image

Medium

Problem statement

You are given an n x n 2D matrix representing an image. Rotate the image 90 degrees clockwise in-place.

Approach and explanation

Transpose the matrix, then reverse each row. That sequence equals a 90° clockwise rotation.

Time complexity: O(n²) Space complexity: O(1) Category: Math & Geometry

JavaScript solution

function rotate(matrix) {
  const n = matrix.length;
  for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
      [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
    }
  }
  for (const row of matrix) row.reverse();
}

69. Spiral Matrix

Medium

Problem statement

Given an m x n matrix, return all elements of the matrix in spiral order.

Approach and explanation

Maintain top/bottom/left/right bounds. Traverse right, down, left, up layers, shrinking bounds after each side.

Time complexity: O(m n) Space complexity: O(1) extra Category: Math & Geometry

JavaScript solution

function spiralOrder(matrix) {
  const res = [];
  let top = 0, bottom = matrix.length - 1, left = 0, right = matrix[0].length - 1;
  while (top <= bottom && left <= right) {
    for (let c = left; c <= right; c++) res.push(matrix[top][c]);
    top++;
    for (let r = top; r <= bottom; r++) res.push(matrix[r][right]);
    right--;
    if (top <= bottom) {
      for (let c = right; c >= left; c--) res.push(matrix[bottom][c]);
      bottom--;
    }
    if (left <= right) {
      for (let r = bottom; r >= top; r--) res.push(matrix[r][left]);
      left++;
    }
  }
  return res;
}

70. Set Matrix Zeroes

Medium

Problem statement

Given an m x n integer matrix, if an element is 0, set its entire row and column to 0s. Do it in-place.

Approach and explanation

Use first row/column as markers (plus a flag for first row). First mark, then zero based on markers to achieve O(1) extra space.

Time complexity: O(m n) Space complexity: O(1) Category: Math & Geometry

JavaScript solution

function setZeroes(matrix) {
  const m = matrix.length, n = matrix[0].length;
  let firstRow = false;
  for (let c = 0; c < n; c++) if (matrix[0][c] === 0) firstRow = true;
  for (let r = 1; r < m; r++) {
    for (let c = 0; c < n; c++) {
      if (matrix[r][c] === 0) {
        matrix[r][0] = 0;
        matrix[0][c] = 0;
      }
    }
  }
  for (let r = 1; r < m; r++) {
    for (let c = 1; c < n; c++) {
      if (matrix[r][0] === 0 || matrix[0][c] === 0) matrix[r][c] = 0;
    }
  }
  if (matrix[0][0] === 0) for (let r = 0; r < m; r++) matrix[r][0] = 0;
  if (firstRow) for (let c = 0; c < n; c++) matrix[0][c] = 0;
}

Blind 75 category

Bit Manipulation interview questions

5 Blind 75 problems in bit manipulation.

Back to contents

71. Number of 1 Bits

Easy

Problem statement

Write a function that takes an unsigned integer and returns the number of set bits (Hamming weight).

Approach and explanation

Repeatedly clear the lowest set bit with n &= (n-1) and count. Each iteration removes one 1-bit.

Time complexity: O(k set bits) Space complexity: O(1) Category: Bit Manipulation

JavaScript solution

function hammingWeight(n) {
  let count = 0;
  while (n) {
    n &= n - 1;
    count++;
  }
  return count;
}

72. Counting Bits

Easy

Problem statement

Given integer n, return an array ans of length n+1 where ans[i] is the number of 1s in binary representation of i.

Approach and explanation

DP: ans[i] = ans[i >> 1] + (i & 1). Right shift drops lowest bit; add it back if it was set.

Time complexity: O(n) Space complexity: O(n) Category: Bit Manipulation

JavaScript solution

function countBits(n) {
  const ans = Array(n + 1).fill(0);
  for (let i = 1; i <= n; i++) ans[i] = ans[i >> 1] + (i & 1);
  return ans;
}

73. Reverse Bits

Easy

Problem statement

Reverse bits of a given 32-bit unsigned integer.

Approach and explanation

Build result by taking LSB of n and shifting into result from the right, 32 times.

Time complexity: O(1) Space complexity: O(1) Category: Bit Manipulation

JavaScript solution

function reverseBits(n) {
  let res = 0;
  for (let i = 0; i < 32; i++) {
    res = (res << 1) | (n & 1);
    n >>>= 1;
  }
  return res >>> 0;
}

74. Missing Number

Easy

Problem statement

Given an array nums containing n distinct numbers in range [0, n], return the only number in the range missing from the array.

Approach and explanation

XOR all indices and values: paired numbers cancel, leftover is missing. Gauss sum formula also works.

Time complexity: O(n) Space complexity: O(1) Category: Bit Manipulation

JavaScript solution

function missingNumber(nums) {
  let x = nums.length;
  for (let i = 0; i < nums.length; i++) x ^= i ^ nums[i];
  return x;
}

75. Sum of Two Integers

Medium

Problem statement

Given two integers a and b, return their sum without using the operators + and -.

Approach and explanation

XOR is sum without carry; AND<<1 is carry. Repeat until carry is 0. In JS use |0 to keep 32-bit signed behavior.

Time complexity: O(1) Space complexity: O(1) Category: Bit Manipulation

JavaScript solution

function getSum(a, b) {
  while (b !== 0) {
    const carry = (a & b) << 1;
    a = a ^ b;
    b = carry;
  }
  return a;
}

Common questions

Blind 75 FAQ

What is the Blind 75?

Blind 75 is a curated list of 75 essential coding interview problems covering arrays, hashing, two pointers, sliding windows, trees, graphs, dynamic programming, and more. It is widely used to prepare for software engineering interviews efficiently.

Is Blind 75 enough for coding interviews?

Blind 75 is an excellent core set for fundamentals and patterns. Many candidates start with Blind 75, then expand into company-specific lists, system design, and language or framework interview questions for a complete prep plan.

Should I memorize Blind 75 solutions?

No. Focus on recognizing patterns, explaining trade-offs, and rewriting solutions from first principles. Use each problem to practice timed problem solving, edge cases, and complexity analysis.

Which language should I use for Blind 75?

Use the language you will interview in. This guide provides interview-friendly JavaScript solutions, but the algorithms and patterns transfer cleanly to TypeScript, Python, Java, and C++.

How long does it take to finish Blind 75?

Many candidates complete a first pass in 4 to 8 weeks with consistent daily practice. Revisit harder problems, explain solutions out loud, and time yourself before interviews.

What topics are covered in Blind 75?

This Blind 75 guide includes 17 topic groups such as Arrays & Hashing, Two Pointers, Sliding Window, Trees, Graphs, Dynamic Programming, Intervals, and Bit Manipulation—with 19 easy, 49 medium, and 7 hard problems.

Key takeaways

  • Blind 75 prioritizes high-frequency interview patterns over volume.
  • Explanations matter—practice narrating your approach before coding.
  • Track time and space complexity for every solution you rewrite.
  • Combine DSA practice with role-specific interview questions and topic quizzes.

Next step

After finishing a category, practice the matching language track in JavaScript coding questions or review framework interviews from the interview questions hub.