Structured practice · in your browser
AlgoMindset 75
The 75 problems that cover every core interview pattern. Name the pattern, write JavaScript, and submit against real test cases. A problem is ticked when all its tests pass, and signed-in solves follow you across devices.
75 problems22 patternsHidden test casesVideo for each
0 / 75 solved
to dosolved
Hover a square to see the topic. Click it to open the lesson.
Ticked automatically when all tests pass.Saved in this browser only.
75 topics · 22 groups
All 75, by pattern
Array / String
0/9 solved- 01Merge Strings AlternatelyEasyYou are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.
- 02Greatest Common Divisor of StringsEasyFor two strings s and t, we say "t divides s" if s = t + t + … + t (t concatenated one or more times).
- 03Kids With the Greatest Number of CandiesEasyThere are n kids with candies. Given an array candies (candies[i] = candies of the i-th kid) and extraCandies, return a boolean array result where result[i] is true if, after giving the i-th kid all the extraCandies, they have the greatest number of candies among all kids.
- 04Can Place FlowersEasyYou have a flowerbed in which some plots are planted (1) and some are not (0). Flowers cannot be planted in adjacent plots.
- 05Reverse Vowels of a StringEasyGiven a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u' (both cases).
- 06Reverse Words in a StringMediumGiven an input string s, reverse the order of the words. A word is a maximal substring of non-space characters. Return a string with the words in reverse order joined by a single space, with no leading or trailing spaces.
- 07Product of Array Except SelfMediumGiven an integer array nums, return an array answer such that answer[i] is the product of all the elements of nums except nums[i]. You must not use division, and the algorithm must run in O(n).
- 08Increasing Triplet SubsequenceMediumGiven an integer array nums, return true if there exist indices i < j < k with nums[i] < nums[j] < nums[k]; otherwise return false. Aim for O(n) time and O(1) space.
- 09String CompressionMediumGiven an array of characters chars, compress it in place: consecutive repeating characters become the character followed by the group length (if greater than 1; lengths of 10 or more are split into separate digit characters).
Two Pointers
0/4 solved- 10Move ZeroesEasyGiven an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Do this in place, then return the array.
- 11Is SubsequenceEasyGiven two strings s and t, return true if s is a subsequence of t: s can be formed from t by deleting some (possibly zero) characters without changing the order of the remaining characters.
- 12Container With Most WaterMediumYou are given an integer array height of length n. There are n vertical lines; the i-th line goes from (i, 0) to (i, height[i]). Find two lines that, together with the x-axis, form a container that holds the most water. Return the maximum amount of water it can store.
- 13Max Number of K-Sum PairsMediumYou are given an integer array nums and an integer k. In one operation, pick two numbers from the array whose sum equals k and remove them. Return the maximum number of operations you can perform.
Sliding Window
0/4 solved- 14Maximum Average Subarray IEasyYou are given an integer array nums of n elements and an integer k. Find a contiguous subarray of length exactly k that has the maximum average value, and return this value (answers within 10⁻⁵ are accepted).
- 15Maximum Number of Vowels in a SubstringMediumGiven a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
- 16Max Consecutive Ones IIIMediumGiven a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.
- 17Longest Subarray of 1s After Deleting One ElementMediumGiven a binary array nums, you must delete exactly one element from it. Return the size of the longest non-empty subarray containing only 1s in the resulting array (0 if there is no such subarray).
Prefix Sum
0/2 solved- 18Find the Highest AltitudeEasyA biker starts a trip at altitude 0. Given an array gain where gain[i] is the net gain in altitude between points i and i+1, return the highest altitude reached.
- 19Find Pivot IndexEasyGiven an array of integers nums, return the leftmost pivot index: the index where the sum of all numbers strictly to its left equals the sum of all numbers strictly to its right. Return -1 if no such index exists.
Hash Map / Set
0/4 solved- 20Find the Difference of Two ArraysEasyGiven two integer arrays nums1 and nums2, return a list answer of size 2 where answer[0] is a list of all distinct integers in nums1 not present in nums2, and answer[1] is a list of all distinct integers in nums2 not present in nums1.
- 21Unique Number of OccurrencesEasyGiven an array of integers arr, return true if the number of occurrences of each value in the array is unique, or false otherwise.
- 22Determine if Two Strings Are CloseMediumTwo strings are "close" if you can transform one into the other using: (1) swap any two existing characters, or (2) transform every occurrence of one existing character into another existing character, and vice versa.
- 23Equal Row and Column PairsMediumGiven an n x n integer matrix grid, return the number of pairs (rᵢ, cⱼ) such that row rᵢ and column cⱼ are equal (contain the same elements in the same order).
Stack
0/3 solved- 24Removing Stars From a StringMediumYou are given a string s containing stars '*'. In one operation, choose a star, remove the closest non-star character to its left, and remove the star itself. Return the string after all stars have been removed.
- 25Asteroid CollisionMediumWe are given an array asteroids: the absolute value is its size, the sign its direction (positive = right, negative = left). All move at the same speed. When two asteroids meet, the smaller explodes (both explode if equal). Asteroids moving the same direction never meet.
- 26Decode StringMediumGiven an encoded string, return its decoded string. The encoding rule is k[encoded_string], where the encoded_string inside the brackets is repeated exactly k times. Nesting is allowed.
Queue
0/2 solved- 27Number of Recent CallsEasyImplement a RecentCounter class that counts recent requests within a 3000 millisecond window. ping(t) records a request at time t (strictly increasing) and returns the number of requests in [t - 3000, t].
- 28Dota2 SenateMediumThe Dota2 senate consists of Radiant (R) and Dire (D) senators voting in rounds. Each senator can ban one senator from the other party in order. Rounds repeat with the surviving senators until one party remains. All senators play optimally.
Linked List
0/4 solved- 29Delete the Middle Node of a Linked ListMediumGiven the head of a linked list, delete the middle node (the ⌊n/2⌋-th node, 0-indexed) and return the head of the modified list.
- 30Odd Even Linked ListMediumGiven the head of a singly linked list, group all the nodes at odd positions together followed by the nodes at even positions (1-indexed), keeping relative order within each group. Solve in O(1) space and O(n) time.
- 31Reverse Linked ListEasyGiven the head of a singly linked list, reverse the list and return the new head.
- 32Maximum Twin Sum of a Linked ListMediumIn a linked list of even length n, node i is the twin of node n-1-i (0-indexed). The twin sum is node.val + twin.val. Given the head of a linked list of even length, return the maximum twin sum.
Binary Tree — DFS
0/6 solved- 33Maximum Depth of Binary TreeEasyGiven the root of a binary tree, return its maximum depth: the number of nodes along the longest path from the root node down to the farthest leaf node.
- 34Leaf-Similar TreesEasyThe leaf value sequence of a binary tree is the values of its leaves read from left to right. Two trees are leaf-similar if their leaf value sequences are the same. Given the roots of two trees, return true if they are leaf-similar.
- 35Count Good Nodes in Binary TreeMediumA node X in a binary tree is "good" if on the path from the root to X there are no nodes with a value greater than X. Return the number of good nodes.
- 36Path Sum IIIMediumGiven the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum. A path must go downwards (parent to child) but need not start at the root or end at a leaf.
- 37Longest ZigZag Path in a Binary TreeMediumA ZigZag path starts at any node, moves to a child, then keeps alternating direction (left, right, left, …). The length is the number of nodes visited − 1. Given the root of a binary tree, return the longest ZigZag path length.
- 38Lowest Common Ancestor of a Binary TreeMediumGiven a binary tree and two nodes p and q, return their lowest common ancestor (LCA): the lowest node that has both p and q as descendants (a node can be a descendant of itself).
Binary Tree — BFS
0/2 solved- 39Binary Tree Right Side ViewMediumGiven the root of a binary tree, imagine standing on its right side. Return the values of the nodes you can see, ordered from top to bottom.
- 40Maximum Level Sum of a Binary TreeMediumGiven the root of a binary tree with levels numbered from 1, return the smallest level x such that the sum of all node values at level x is maximal.
Binary Search Tree
0/2 solved- 41Search in a Binary Search TreeEasyYou are given the root of a binary search tree (BST) and an integer val. Find the node whose value equals val and return the subtree rooted at that node (null if it does not exist).
- 42Delete Node in a BSTMediumGiven a BST root and a key, delete the node with the given key (if it exists) and return the root. The result must remain a valid BST — any valid rebalancing (successor or predecessor replacement) is accepted.
Graphs — DFS
0/4 solved- 43Keys and RoomsMediumThere are n rooms labeled 0..n-1; all rooms are locked except room 0. rooms[i] is the list of keys found in room i. Return true if you can visit all the rooms.
- 44Number of ProvincesMediumThere are n cities. isConnected[i][j] = 1 means cities i and j are directly connected. A province is a group of directly or indirectly connected cities. Return the total number of provinces.
- 45Reorder Routes to Lead to City ZeroMediumThere are n cities and n-1 directed roads connections (a tree if undirected). Reorient the minimum number of roads so every city can reach city 0. Return the minimum number of edges changed.
- 46Evaluate DivisionMediumYou are given equations like a / b = 2.0 as pairs [a, b] with values, and queries [c, d]. Return the answer for each query, or -1.0 if it cannot be determined.
Graphs — BFS
0/2 solved- 47Nearest Exit from Entrance in MazeMediumYou are given an m x n maze of "." (empty) and "+" (wall), and the entrance cell. An exit is an empty cell on the border that is not the entrance. Return the number of steps in the shortest path to the nearest exit, or -1.
- 48Rotting OrangesMediumIn a grid, 0 = empty, 1 = fresh orange, 2 = rotten orange. Every minute, fresh oranges 4-directionally adjacent to a rotten one become rotten. Return the minimum minutes until no fresh orange remains, or -1 if impossible.
Heap / Priority Queue
0/4 solved- 49Kth Largest Element in an ArrayMediumGiven an integer array nums and an integer k, return the k-th largest element in the array (in sorted order, not the k-th distinct element).
- 50Smallest Number in Infinite SetMediumYou have a set containing all positive integers [1, 2, 3, …]. Implement SmallestInfiniteSet: popSmallest() removes and returns the smallest integer in the set; addBack(num) adds num back if it was removed.
- 51Maximum Subsequence ScoreMediumYou are given two arrays nums1 and nums2 of length n, and an integer k. Choose k indices; the score is (sum of chosen nums1 values) × (minimum of chosen nums2 values). Return the maximum possible score.
- 52Total Cost to Hire K WorkersMediumcosts[i] is the cost of hiring the i-th worker. Run k hiring sessions: in each, consider the first `candidates` workers and the last `candidates` workers still available, and hire the one with the lowest cost (lowest index on ties). Return the total cost to hire k workers.
Binary Search
0/4 solved- 53Guess Number Higher or LowerEasyI picked a number between 1 and n. You call the provided guess(num) API: it returns 0 if num is my number, -1 if my number is lower, and 1 if my number is higher. Return the number I picked.
- 54Successful Pairs of Spells and PotionsMediumGiven arrays spells and potions and an integer success, a pair (spell, potion) is successful if spell × potion ≥ success. For each spell, return how many potions form a successful pair with it.
- 55Koko Eating BananasMediumKoko has piles of bananas and h hours. Each hour she eats up to k bananas from one pile. Return the minimum integer k so she can eat all the bananas within h hours.
- 56Find Peak ElementMediumA peak element is strictly greater than its neighbors (nums[-1] and nums[n] are -∞). Given nums where no two adjacent elements are equal, return the index of any peak, in O(log n) time.
Backtracking
0/2 solved- 57Letter Combinations of a Phone NumberMediumGiven a string containing digits 2-9, return all possible letter combinations the number could represent on a phone keypad, in any order.
- 58Combination Sum IIIMediumFind all valid combinations of k numbers that sum to n, using only numbers 1 through 9, each at most once. Return the list of all such combinations (no duplicates).
DP — 1D
0/4 solved- 59N-th Tribonacci NumberEasyThe Tribonacci sequence: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2. Given n, return the value of Tn.
- 60Min Cost Climbing StairsEasycost[i] is the cost of the i-th step; after paying you can climb one or two steps. You can start from step 0 or step 1. Return the minimum cost to reach the top of the floor (past the last step).
- 61House RobberMediumYou cannot rob two adjacent houses. Given an array nums of money in each house, return the maximum amount you can rob tonight without alerting the police.
- 62Domino and Tromino TilingMediumYou can tile a 2 x n board with 2 x 1 dominoes and L-shaped trominoes (rotations allowed). Return the number of ways to fully tile the board, modulo 10⁹ + 7.
DP — Multidimensional
0/4 solved- 63Unique PathsMediumA robot starts at the top-left of an m x n grid and can only move right or down. Return the number of unique paths to reach the bottom-right corner.
- 64Longest Common SubsequenceMediumGiven two strings text1 and text2, return the length of their longest common subsequence (characters in order, not necessarily contiguous), or 0 if there is none.
- 65Best Time to Buy and Sell Stock with Transaction FeeMediumGiven prices[i] (price on day i) and a transaction fee, you may complete as many transactions as you like (pay the fee per transaction, hold at most one share). Return the maximum profit.
- 66Edit DistanceMediumGiven two strings word1 and word2, return the minimum number of operations (insert, delete, or replace a character) required to convert word1 into word2.
Bit Manipulation
0/3 solved- 67Counting BitsEasyGiven an integer n, return an array ans of length n + 1 such that ans[i] is the number of 1's in the binary representation of i.
- 68Single NumberEasyGiven a non-empty array of integers nums, every element appears twice except for one. Find that single one, in linear time and constant space.
- 69Minimum Flips to Make a OR b Equal to cMediumGiven three positive integers a, b, and c, return the minimum number of bit flips required in a and b so that (a OR b) equals c.
Trie
0/2 solved- 70Implement Trie (Prefix Tree)MediumImplement the Trie class: insert(word) stores a word; search(word) returns true if word was inserted; startsWith(prefix) returns true if any inserted word has the given prefix.
- 71Search Suggestions SystemMediumGiven an array of product names and a searchWord, after each character of searchWord is typed, suggest at most three lexicographically smallest products with the current prefix. Return the list of suggestion lists.
Intervals
0/2 solved- 72Non-overlapping IntervalsMediumGiven an array of intervals [start, end], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
- 73Minimum Number of Arrows to Burst BalloonsMediumBalloons are intervals [xstart, xend] on the x-axis. An arrow shot at x bursts every balloon with xstart ≤ x ≤ xend. Return the minimum number of arrows to burst all balloons.
Monotonic Stack
0/2 solved- 74Daily TemperaturesMediumGiven an array temperatures, return an array answer where answer[i] is the number of days you have to wait after day i to get a warmer temperature (0 if none).
- 75Online Stock SpanMediumImplement StockSpanner: next(price) returns the span of today's price — the number of consecutive days (ending today, going backward) the price was less than or equal to today's price.