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
#260Medium

Single Number III

ArrayBit Manipulation

Acceptance: 70.2%

#261Medium

Graph Valid Tree

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 49.9%

#264Medium

Ugly Number II

Dynamic ProgrammingHash TableHeap (Priority Queue)+1

Acceptance: 49.7%

#267Medium

Palindrome Permutation II

BacktrackingHash TableString

Acceptance: 41.9%

#271Medium

Encode and Decode Strings

ArrayDesignString

Acceptance: 51.9%

#274Medium

H-Index

ArrayCounting SortSorting

Acceptance: 41.8%

#275Medium

H-Index II

ArrayBinary Search

Acceptance: 40.0%

#276Medium

Paint Fence

Dynamic Programming

Acceptance: 48.3%

#277Medium

Find the Celebrity

GraphInteractiveTwo Pointers

Acceptance: 48.9%

#279Medium

Perfect Squares

Breadth-First SearchDynamic ProgrammingMath

Acceptance: 56.4%

#280Medium

Wiggle Sort

ArrayGreedySorting

Acceptance: 68.5%

#281Medium

Zigzag Iterator

ArrayDesignIterator+1

Acceptance: 67.1%

#284Medium

Peeking Iterator

ArrayDesignIterator

Acceptance: 61.9%

#285Medium

Inorder Successor in BST

Binary Search TreeBinary TreeDepth-First Search+1

Acceptance: 51.2%

#286Medium

Walls and Gates

ArrayBreadth-First SearchMatrix

Acceptance: 63.9%

#287Medium

Find the Duplicate Number

ArrayBinary SearchBit Manipulation+1

Acceptance: 64.7%

#288Medium

Unique Word Abbreviation

ArrayDesignHash Table+1

Acceptance: 27.5%

#289Medium

Game of Life

ArrayMatrixSimulation

Acceptance: 73.0%

#291Medium

Word Pattern II

BacktrackingHash TableString

Acceptance: 49.1%

#294Medium

Flip Game II

BacktrackingDynamic ProgrammingGame Theory+2

Acceptance: 52.2%

#298Medium

Binary Tree Longest Consecutive Sequence

Binary TreeDepth-First SearchTree

Acceptance: 54.7%

#299Medium

Bulls and Cows

CountingHash TableString

Acceptance: 52.9%

#300Medium

Longest Increasing Subsequence

ArrayBinary SearchDynamic Programming

Acceptance: 59.8%

#304Medium

Range Sum Query 2D - Immutable

ArrayDesignMatrix+1

Acceptance: 58.6%

#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%

#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%

#316Medium

Remove Duplicate Letters

GreedyMonotonic StackStack+1

Acceptance: 54.1%

#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%

#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%

#328Medium

Odd Even Linked List

Linked List

Acceptance: 62.4%

#331Medium

Verify Preorder Serialization of a Binary Tree

Binary TreeStackString+1

Acceptance: 47.8%

#333Medium

Largest BST Subtree

Binary Search TreeBinary TreeDepth-First Search+2

Acceptance: 45.8%

#334Medium

Increasing Triplet Subsequence

ArrayGreedy

Acceptance: 39.3%

#337Medium

House Robber III

Binary TreeDepth-First SearchDynamic Programming+1

Acceptance: 56.3%

#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%

#343Medium

Integer Break

Dynamic ProgrammingMath

Acceptance: 62.6%

#347Medium

Top K Frequent Elements

ArrayBucket SortCounting+5

Acceptance: 67.3%

Page 4 of 43

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