Coders Crushby Napplied AI

Data Structures & Algorithms

100+ curated problems from top tech interviews

AllArrays & HashingTwo PointersSliding WindowStack & QueueBinary SearchLinked ListsTreesTriesHeap / Priority QueueGraphsDynamic ProgrammingBacktrackingGreedyIntervalsMath & GeometryBit Manipulation

129 problems found

Level Order Traversal

MediumTrees

BFS level by level...

O(V + E) / O(V)
Google, Amazon

Happy Number

Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless

EasyMath & Geometry

Check if number is happy...

O(log n) / O(1)
Google, Facebook

Is Palindrome II

EasyTwo Pointers

Check palindrome with alphanumeric only...

O(n) / O(1)
Facebook, Apple

Majority Element

EasyArrays & Hashing

Find element appearing > n/2 times...

O(n) / O(1)
Facebook, Microsoft

Number of 1 Bits

EasyBit Manipulation

Count 1 bits in integer...

O(1) / O(1)
Google, Microsoft

Add Two Numbers

MediumLinked Lists

Add two numbers represented by lists...

O(max(m,n)) / O(max(m,n))
Google, Amazon

Reorder List

MediumLinked Lists

Reorder list in alternating pattern...

O(n) / O(1)
Google, Facebook

Number of Recent Calls

EasyStack & Queue

Recent request count in range...

O(1) / O(n)
Google, Amazon

Path Sum

EasyTrees

Check if root-leaf path equals target...

O(n) / O(h)
Google, Microsoft

Reverse Bits

EasyBit Manipulation

Reverse bits of integer...

O(1) / O(1)
Microsoft, Amazon

Reverse String

EasyTwo Pointers

Reverse character array in-place...

O(n) / O(1)
Google, Amazon

Search Insert Position

EasyBinary Search

Find position to insert target...

O(log n) / O(1)
Google, Facebook

Single Number

EasyBit Manipulation

Find single number in array...

O(n) / O(1)
Google, Amazon

Network Delay Time

MediumGraphs

Time for all nodes to receive signal...

O(n*log n + e) / O(n)
Google, Amazon

Sqrt(x)

EasyMath & Geometry

Integer square root...

O(log n) / O(1)
Google, Amazon

Autocomplete System

HardTries

Implement autocomplete...

O(n*log n) / O(n)
Google, Amazon

Binary Tree Maximum Path Sum

HardTrees

Find max sum path in tree...

O(n) / O(h)
Google, Amazon

Remove Nth Node From End of List

MediumTwo Pointers

Remove nth node from linked list...

O(n) / O(1)
Google, Apple

Longest Repeating Character Replacement

MediumSliding Window

Max length after k character replacements...

O(n) / O(1)
Google, Amazon

Find First and Last Position

MediumBinary Search

Find range of target in sorted array...

O(log n) / O(1)
Google, Microsoft

Time Based Key-Value Store

MediumBinary Search

Query key value at timestamp...

O(log n) / O(n)
Google, Amazon

Max Consecutive Ones III

MediumSliding Window

Max ones after flipping k zeros...

O(n) / O(1)
Facebook, Google

Substring with Concatenation of All Words

HardSliding Window

Find all substrings with concatenated words...

O(n*m) / O(m)
Google, Amazon

4Sum

MediumTwo Pointers

Find all unique quadruplets...

O(n³) / O(1)
Google, Facebook

Koko Eating Bananas

MediumBinary Search

Find min eating speed for h hours...

O(n*log m) / O(1)
Google, Facebook

Implement Trie

MediumTries

Implement prefix tree...

O(m) / O(1)
Google, Amazon

Fruit Into Baskets

MediumSliding Window

Max fruit with at most 2 types...

O(n) / O(1)
Google, Amazon

Minimum Size Subarray Sum

MediumSliding Window

Find minimum length subarray with sum >= target...

O(n) / O(1)
Amazon, Google

Graph Valid Tree

MediumGraphs

Check if graph is valid tree...

O(n) / O(n)
Google, Amazon

Number of Connected Components

MediumGraphs

Count connected components...

O(n+e) / O(n)
Google, Facebook

Evaluate Reverse Polish Notation

MediumStack & Queue

Evaluate RPN expression...

O(n) / O(n)
Google, Amazon

Largest Rectangle in Histogram

HardStack & Queue

Largest rectangle in histogram...

O(n) / O(n)
Google, Microsoft

Simplify Path

MediumStack & Queue

Simplify Unix file path...

O(n) / O(n)
Google, Facebook

Word Search

MediumBacktracking

Search word in 2D grid...

O(m*n*4^L) / O(L)
Google, Amazon

Palindrome Partitioning

MediumBacktracking

Partition string into palindromes...

O(n*2^n) / O(n)
Google, Facebook

Subset Sum

MediumBacktracking

Check if subset sum exists...

O(2^n) / O(n)
Google, Amazon

Gas Station

MediumGreedy

Find start gas station...

O(n) / O(1)
Google, Amazon

Bitwise AND of Range

MediumBit Manipulation

Bitwise AND of range...

O(log n) / O(1)
Google, Facebook

Pow(x, n)

MediumMath & Geometry

Calculate x^n...

O(log n) / O(log n)
Google, Amazon

Fraction to Recurring Decimal

MediumMath & Geometry

Convert fraction to decimal...

O(d) / O(d)
Google, Amazon

Alien Dictionary

HardGraphs

Order characters from alien dictionary...

O(n) / O(1)
Google, Facebook

Daily Temperatures

MediumStack & Queue

Days until warmer temperature...

O(n) / O(n)
Google, Amazon

Replace Words

MediumTries

Replace words with dictionary root...

O(n*m*k) / O(t)
Google, Facebook

Kth Largest Element

MediumHeap / Priority Queue

Find kth largest element...

O(n*log k) / O(k)
Google, Amazon

Reorganize String

MediumHeap / Priority Queue

Reorganize string by frequency...

O(n*log n) / O(n)
Google, Amazon

Meeting Rooms II

MediumIntervals

Minimum conference rooms needed...

O(n*log n) / O(n)
Google, Amazon

Longest Substring Without Repeating

MediumSliding Window

Find longest substring without repeating...

O(n) / O(min(m, n))
Google, Amazon

Reverse Linked List

EasyLinked Lists

Reverse singly linked list...

O(n) / O(1)
Google, Amazon

First Bad Version

EasyBinary Search

Find first bad version...

O(log n) / O(1)
Google, Facebook

Candy

HardGreedy

Minimum candies for children...

O(n) / O(n)
Google, Amazon

Find Median from Data Stream

HardHeap / Priority Queue

Find median with streaming numbers...

O(log n) / O(n)
Google, Amazon

Word Search II

HardTries

Search words in grid using trie...

O(m*n*4^L) / O(t)
Google, Amazon

Palindrome Linked List

EasyLinked Lists

Check if linked list is palindrome...

O(n) / O(1)
Google, Facebook

Valid Parentheses

EasyStack & Queue

Check if parentheses are valid...

O(n) / O(n)
Google, Amazon

Inorder Traversal

EasyTrees

Inorder tree traversal...

O(n) / O(h)
Google, Amazon

Maximum Depth of Binary Tree

EasyTrees

Find max depth of tree...

O(n) / O(h)
Google, Amazon

Same Tree

EasyTrees

Check if two trees are same...

O(min(m,n)) / O(min(h1,h2))
Google, Amazon

Generate Parentheses

MediumBacktracking

Generate valid parentheses combinations...

O(4^n/√n) / O(n)
Google, Amazon

Best Time to Buy and Sell Stock

EasySliding Window

Find max profit from one transaction...

O(n) / O(1)
Google, Amazon

Jump Game

MediumDynamic Programming

Can reach last index...

O(n) / O(1)
Google, Amazon

Jump Game II

MediumGreedy

Minimum jumps to reach end...

O(n) / O(1)
Google, Amazon

Permutation in String

MediumSliding Window

Check if s1 permutation in s2...

O(n!) / O(n)
Google, Amazon

Combinations

MediumBacktracking

Generate all k-combinations...

O(n!) / O(n)
Google, Amazon

Lowest Common Ancestor of BST

MediumTrees

Find LCA in binary search tree...

O(h) / O(1)
Google, Amazon

Binary Tree Right Side View

MediumTrees

Get rightmost nodes at each level...

O(n) / O(h)
Google, Amazon

Letter Combinations Phone Number

MediumBacktracking

Letter combinations of phone number...

O(n!) / O(n)
Google, Amazon

Validate Binary Search Tree

MediumTrees

Check if tree is valid BST...

O(log n) / O(1)
Google, Amazon

Interval Scheduling

MediumGreedy

Maximum non-overlapping intervals...

O(n log n) / O(1)
Google, Amazon

Non-overlapping Intervals

MediumIntervals

Remove minimum intervals for non-overlap...

O(n log n) / O(1)
Google, Facebook

Implement Queue using Stacks

EasyStack & Queue

Queue using two stacks...

O(n) / O(n)
Google, Microsoft

Min Stack

MediumStack & Queue

Stack supporting min queries...

O(n) / O(n)
Google, Amazon

Two Sum II Input Array Sorted

EasyTwo Pointers

Find two numbers in sorted array...

O(n log n) / O(n)
Amazon, Google

Merge Sorted Array

EasyTwo Pointers

Merge two sorted arrays in-place...

O(n log n) / O(n)
Google, Microsoft

Search in Rotated Sorted Array

MediumBinary Search

Find target in rotated array...

O(n log n) / O(n)
Google, Microsoft

Median of Two Sorted Arrays

HardBinary Search

Find median of two sorted arrays...

O(n log n) / O(n)
Google, Microsoft

Serialize and Deserialize Binary Tree

HardTrees

Convert tree to/from string...

O(n) / O(n)
Google, Amazon

Construct Binary Tree from Preorder and Inorder

MediumTrees

Build tree from traversals...

O(n) / O(n)
Google, Amazon

Merge Two Sorted Lists

EasyLinked Lists

Merge two sorted linked lists...

O(n log n) / O(n)
Google, Amazon

Remove Duplicates from Sorted List

EasyLinked Lists

Remove duplicates in sorted list...

O(n log n) / O(n)
Google, Microsoft

Merge k Sorted Lists

HardHeap / Priority Queue

Merge k sorted linked lists...

O(n log n) / O(n)
Google, Amazon

Insert Interval

HardIntervals

Insert interval into sorted list...

O(n log n) / O(1)
Google, Amazon

Longest Consecutive

MediumArrays & Hashing

Find longest consecutive sequence...

O(n) / O(n)
Google, Facebook

Valid Sudoku

MediumArrays & Hashing

Validate sudoku board...

O(1) / O(1)
Apple, Uber

Encode and Decode Strings

MediumArrays & Hashing

Encode/decode list of strings...

O(n) / O(n)
Google, Amazon

House Robber

MediumDynamic Programming

Maximum sum without adjacent elements...

O(n) / O(1)
Google, Amazon

Coin Change II

MediumDynamic Programming

Number of ways to make amount...

O(n*m) / O(n)
Google, Amazon

Spiral Matrix

MediumArrays & Hashing

Traverse matrix in spiral order...

O(m*n) / O(1)
Google, Amazon

Copy List with Random Pointer

MediumLinked Lists

Deep copy list with random pointers...

O(n) / O(n)
Google, Amazon

Unique Paths

MediumDynamic Programming

Number of paths in grid...

O(m*n) / O(1)
Google, Amazon

Decode Ways

MediumDynamic Programming

Number of ways to decode string...

O(n) / O(1)
Google, Amazon

Maximum Subarray

MediumDynamic Programming

Find max sum contiguous subarray...

O(n) / O(1)
Google, Amazon

Burst Balloons

HardDynamic Programming

Maximum coins from bursting balloons...

O(n³) / O(n²)
Google, Amazon

Clone Graph

MediumGraphs

Deep copy undirected graph...

O(n+e) / O(n)
Google, Amazon

Cheapest Flights Within K Stops

MediumGraphs

Shortest path with at most k stops...

O(n*k) / O(n)
Google, Amazon

Surrounded Regions

MediumGraphs

Flip surrounded regions...

O(m*n) / O(m*n)
Google, Facebook

Set Matrix Zeroes

MediumArrays & Hashing

Set entire row/col to 0 if element is 0...

O(m*n) / O(1)
Google, Microsoft

3Sum

MediumTwo Pointers

Find all unique triplets summing to 0...

O(n²) / O(1)
Google, Facebook

Merge Intervals

#56
MediumIntervals

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals...

O(n log n) / O(1)
Google, Amazon

Word Ladder

#127
HardGraphs

A transformation sequence from beginWord to endWord using dictionary wordList is a sequence where every adjacent pair of words differs by a single let...

O(M² * N) / O(M * N)
Google, Amazon

Number of Islands

#200
MediumGraphs

Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by wa...

O(V + E) / O(V)
Google, Amazon

LRU Cache

#146
MediumStack & Queue

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class with get and put operations in...

O(1) / O(capacity)
Google, Amazon

Course Schedule

#207
MediumGraphs

There are a total of numCourses courses you have to take. Some courses may have prerequisites. Given the total number of courses and a list of prerequ...

O(V + E) / O(V + E)
Google, Amazon

N-Queens

#51
HardBacktracking

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return al...

O(n!) / O(n²)
Google, Amazon

Permutations

#46
MediumBacktracking

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order....

O(n!) / O(n)
Google, Amazon

Subsets

#78
MediumBacktracking

Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets....

O(n * 2^n) / O(n)
Google, Amazon

Binary Tree Maximum Path Sum

#124
HardTrees

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. The path sum of a path i...

O(n) / O(h)
Google, Amazon

Search in Rotated Sorted Array

#33
MediumBinary Search

There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at a...

O(n log n) / O(n)
Google, Amazon

Lowest Common Ancestor of BST

#235
MediumTrees

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST....

O(h) / O(1)
Google, Amazon

Edit Distance

#72
MediumDynamic Programming

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You have the following three operations...

O(mn) / O(mn)
Google, Amazon

Climbing Stairs

#70
EasyDynamic Programming

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ...

O(n) / O(1)
Google, Amazon

Coin Change

#322
MediumDynamic Programming

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return ...

O(amount * n) / O(amount)
Google, Amazon

Word Break

#139
MediumDynamic Programming

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

O(n² * m) / O(n)
Google, Amazon

Longest Increasing Subsequence

#300
MediumDynamic Programming

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

O(n log n) / O(n)
Google, Amazon

Invert Binary Tree

#226
EasyTrees

Given the root of a binary tree, invert the tree, and return its root....

O(n) / O(h)
Google, Amazon

Binary Search

#704
EasyBinary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists...

O(log n) / O(1)
Google, Amazon

Longest Substring Without Repeating Characters

#3
MediumSliding Window

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

O(n) / O(min(m, n))
Google, Amazon

Valid Palindrome

#125
EasyTwo Pointers

A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the ...

O(n) / O(1)
Google, Amazon

3Sum

#15
MediumTwo Pointers

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k]...

O(n²) / O(1)
Google, Amazon

Container With Most Water

#11
MediumTwo Pointers

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, hei...

O(n) / O(1)
Google, Amazon

Minimum Window Substring

#76
HardSliding Window

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicat...

O(m + n) / O(m + n)
Google, Amazon

Trapping Rain Water

#42
HardTwo Pointers

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining....

O(n) / O(1)
Google, Amazon

Sliding Window Maximum

#239
HardSliding Window

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You ca...

O(n) / O(min(m, n))
Google, Amazon

Group Anagrams

#49
MediumArrays & Hashing

Given an array of strings strs, group the anagrams together. You can return the answer in any order....

O(n) / O(n)
Google, Amazon

Contains Duplicate

#217
EasyArrays & Hashing

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

O(n) / O(n)
Google, Amazon

Valid Anagram

#242
EasyArrays & Hashing

Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters ...

O(n) / O(n)
Google, Amazon

Top K Frequent Elements

#347
MediumArrays & Hashing

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

O(n) / O(n)
Google, Amazon

Two Sum

#1
EasyArrays & Hashing

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each inp...

O(n) / O(n)
Google, Amazon

Longest Consecutive Sequence

#128
MediumArrays & Hashing

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n...

O(n) / O(n)
Google, Amazon

Product of Array Except Self

#238
MediumArrays & Hashing

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. You must w...

O(n) / O(1)
Google, Amazon