Skip to main content

Solutions & Explanations

Browse 4,029+ detailed solutions with multiple approaches, code in Python, Java, C++ and more.

4,029 Solutions961 Easy2102 Medium966 Hard
#301Hard

Remove Invalid Parentheses

BacktrackingBreadth-First SearchString

Acceptance: 49.8%

#302Hard

Smallest Rectangle Enclosing Black Pixels

ArrayBinary SearchBreadth-First Search+2

Acceptance: 60.9%

#303Easy

Range Sum Query - Immutable

ArrayDesignPrefix Sum

Acceptance: 73.5%

#304Medium

Range Sum Query 2D - Immutable

ArrayDesignMatrix+1

Acceptance: 58.6%

#305Hard

Number of Islands II

ArrayHash TableUnion Find

Acceptance: 40.5%

#306Medium

Additive Number

BacktrackingString

Acceptance: 34.2%

#307Medium

Range Sum Query - Mutable

ArrayBinary Indexed TreeDesign+1

Acceptance: 43.3%

#308Medium

Range Sum Query 2D - Mutable

ArrayBinary Indexed TreeDesign+2

Acceptance: 46.0%

#309Medium

Best Time to Buy and Sell Stock with Cooldown

ArrayDynamic Programming

Acceptance: 62.4%

#310Medium

Minimum Height Trees

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 42.4%

#311Medium

Sparse Matrix Multiplication

ArrayHash TableMatrix

Acceptance: 69.3%

#312Hard

Burst Balloons

ArrayDynamic Programming

Acceptance: 64.3%

#313Medium

Super Ugly Number

ArrayDynamic ProgrammingMath

Acceptance: 46.6%

#314Medium

Binary Tree Vertical Order Traversal

Binary TreeBreadth-First SearchDepth-First Search+3

Acceptance: 57.8%

#315Hard

Count of Smaller Numbers After Self

ArrayBinary Indexed TreeBinary Search+4

Acceptance: 44.0%

#316Medium

Remove Duplicate Letters

GreedyMonotonic StackStack+1

Acceptance: 54.1%

#317Hard

Shortest Distance from All Buildings

ArrayBreadth-First SearchMatrix

Acceptance: 44.9%

#318Medium

Maximum Product of Word Lengths

ArrayBit ManipulationString

Acceptance: 61.1%

#319Medium

Bulb Switcher

BrainteaserMath

Acceptance: 56.2%

#320Medium

Generalized Abbreviation

BacktrackingBit ManipulationString

Acceptance: 60.4%

#321Hard

Create Maximum Number

ArrayGreedyMonotonic Stack+2

Acceptance: 36.7%

#322Medium

Coin Change

ArrayBreadth-First SearchDynamic Programming

Acceptance: 48.7%

#323Medium

Number of Connected Components in an Undirected Graph

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 64.9%

#324Medium

Wiggle Sort II

ArrayDivide and ConquerGreedy+2

Acceptance: 38.4%

#325Medium

Maximum Size Subarray Sum Equals k

ArrayHash TablePrefix Sum

Acceptance: 50.8%

#326Easy

Power of Three

MathRecursion

Acceptance: 51.4%

#327Hard

Count of Range Sum

ArrayBinary Indexed TreeBinary Search+4

Acceptance: 39.7%

#328Medium

Odd Even Linked List

Linked List

Acceptance: 62.4%

#329Hard

Longest Increasing Path in a Matrix

ArrayBreadth-First SearchDepth-First Search+5

Acceptance: 57.0%

#330Hard

Patching Array

ArrayGreedy

Acceptance: 54.7%

#331Medium

Verify Preorder Serialization of a Binary Tree

Binary TreeStackString+1

Acceptance: 47.8%

#332Hard

Reconstruct Itinerary

Depth-First SearchEulerian CircuitGraph

Acceptance: 45.0%

#333Medium

Largest BST Subtree

Binary Search TreeBinary TreeDepth-First Search+2

Acceptance: 45.8%

#334Medium

Increasing Triplet Subsequence

ArrayGreedy

Acceptance: 39.3%

#335Hard

Self Crossing

ArrayGeometryMath

Acceptance: 36.3%

#336Hard

Palindrome Pairs

ArrayHash TableString+1

Acceptance: 37.1%

#337Medium

House Robber III

Binary TreeDepth-First SearchDynamic Programming+1

Acceptance: 56.3%

#338Easy

Counting Bits

Bit ManipulationDynamic Programming

Acceptance: 80.5%

#339Medium

Nested List Weight Sum

Breadth-First SearchDepth-First Search

Acceptance: 85.9%

#340Medium

Longest Substring with At Most K Distinct Characters

Hash TableSliding WindowString

Acceptance: 49.9%

#341Medium

Flatten Nested List Iterator

Depth-First SearchDesignIterator+3

Acceptance: 65.6%

#342Easy

Power of Four

Bit ManipulationMathRecursion

Acceptance: 52.5%

#343Medium

Integer Break

Dynamic ProgrammingMath

Acceptance: 62.6%

#344Easy

Reverse String

StringTwo Pointers

Acceptance: 81.2%

#345Easy

Reverse Vowels of a String

StringTwo Pointers

Acceptance: 62.1%

#346Easy

Moving Average from Data Stream

ArrayData StreamDesign+1

Acceptance: 80.2%

#347Medium

Top K Frequent Elements

ArrayBucket SortCounting+5

Acceptance: 67.3%

#348Medium

Design Tic-Tac-Toe

ArrayDesignHash Table+2

Acceptance: 58.8%

#349Easy

Intersection of Two Arrays

ArrayBinary SearchHash Table+2

Acceptance: 78.2%

#350Easy

Intersection of Two Arrays II

ArrayBinary SearchHash Table+2

Acceptance: 60.4%

Page 7 of 81

Master DSA with Step-by-Step Solutions

Each solution article on FleetCode breaks down the problem into multiple approaches, from brute force to optimal, with detailed explanations and code in Python, Java, C++ and more. Understanding why an approach works - not just copying code - is what separates candidates who clear interviews from those who don't.

How to Use These Solutions

  • Try the problem first: Spend at least 20 minutes before reading the solution
  • Read all approaches: Start from brute force to understand the problem fully, then study the optimized solution
  • Understand the complexity: Pay attention to time and space analysis for each approach
  • Code it yourself: After understanding the approach, close the solution and implement from memory
  • Revisit after a week: Spaced repetition helps retain problem-solving patterns