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

Longest Uncommon Subsequence II

ArrayHash TableSorting+2

Acceptance: 45.2%

#523Medium

Continuous Subarray Sum

ArrayHash TableMath+1

Acceptance: 31.3%

#524Medium

Longest Word in Dictionary through Deleting

ArraySortingString+1

Acceptance: 52.6%

#525Medium

Contiguous Array

ArrayHash TablePrefix Sum

Acceptance: 52.2%

#526Medium

Beautiful Arrangement

ArrayBacktrackingBit Manipulation+2

Acceptance: 64.9%

#528Medium

Random Pick with Weight

ArrayBinary SearchMath+2

Acceptance: 49.0%

#529Medium

Minesweeper

ArrayBreadth-First SearchDepth-First Search+1

Acceptance: 68.7%

#531Medium

Lonely Pixel I

ArrayHash TableMatrix

Acceptance: 62.3%

#532Medium

K-diff Pairs in an Array

ArrayBinary SearchHash Table+2

Acceptance: 46.3%

#533Medium

Lonely Pixel II

ArrayHash TableMatrix

Acceptance: 48.7%

#534Medium

Game Play Analysis III

Database

Acceptance: 81.0%

#535Medium

Encode and Decode TinyURL

DesignHash FunctionHash Table+1

Acceptance: 86.5%

#536Medium

Construct Binary Tree from String

Binary TreeDepth-First SearchStack+2

Acceptance: 58.7%

#537Medium

Complex Number Multiplication

MathSimulationString

Acceptance: 73.3%

#538Medium

Convert BST to Greater Tree

Binary Search TreeBinary TreeDepth-First Search+1

Acceptance: 71.5%

#539Medium

Minimum Time Difference

ArrayMathSorting+1

Acceptance: 62.7%

#540Medium

Single Element in a Sorted Array

ArrayBinary Search

Acceptance: 59.3%

#542Medium

01 Matrix

ArrayBreadth-First SearchDynamic Programming+1

Acceptance: 54.7%

#544Medium

Output Contest Matches

RecursionSimulationString

Acceptance: 77.3%

#545Medium

Boundary of Binary Tree

Binary TreeDepth-First SearchTree

Acceptance: 48.0%

#547Medium

Number of Provinces

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 70.8%

#549Medium

Binary Tree Longest Consecutive Sequence II

Binary TreeDepth-First SearchTree

Acceptance: 50.1%

#550Medium

Game Play Analysis IV

Database

Acceptance: 38.4%

#553Medium

Optimal Division

ArrayDynamic ProgrammingMath

Acceptance: 63.4%

#554Medium

Brick Wall

ArrayHash Table

Acceptance: 56.1%

#555Medium

Split Concatenated Strings

ArrayGreedyString

Acceptance: 43.4%

#556Medium

Next Greater Element III

MathStringTwo Pointers

Acceptance: 35.2%

#558Medium

Logical OR of Two Binary Grids Represented as Quad-Trees

Divide and ConquerTree

Acceptance: 53.3%

#560Medium

Subarray Sum Equals K

ArrayHash TablePrefix Sum

Acceptance: 48.2%

#562Medium

Longest Line of Consecutive One in Matrix

ArrayDynamic ProgrammingMatrix

Acceptance: 50.5%

#565Medium

Array Nesting

ArrayDepth-First Search

Acceptance: 56.6%

#567Medium

Permutation in String

Hash TableSliding WindowString+1

Acceptance: 49.8%

#570Medium

Managers with at Least 5 Direct Reports

Database

Acceptance: 49.4%

#573Medium

Squirrel Simulation

ArrayMath

Acceptance: 57.1%

#574Medium

Winning Candidate

Database

Acceptance: 61.3%

#576Medium

Out of Boundary Paths

Dynamic Programming

Acceptance: 48.1%

#578Medium

Get Highest Answer Rate Question

Database

Acceptance: 40.2%

#580Medium

Count Student Number in Departments

Database

Acceptance: 59.4%

#581Medium

Shortest Unsorted Continuous Subarray

ArrayGreedyMonotonic Stack+3

Acceptance: 38.1%

#582Medium

Kill Process

ArrayBreadth-First SearchDepth-First Search+2

Acceptance: 70.4%

#583Medium

Delete Operation for Two Strings

Dynamic ProgrammingString

Acceptance: 66.0%

#585Medium

Investments in 2016

Database

Acceptance: 49.4%

#592Medium

Fraction Addition and Subtraction

MathSimulationString

Acceptance: 66.6%

#593Medium

Valid Square

GeometryMath

Acceptance: 45.5%

#602Medium

Friend Requests II: Who Has the Most Friends

Database

Acceptance: 59.2%

#606Medium

Construct String from Binary Tree

Binary TreeDepth-First SearchString+1

Acceptance: 70.6%

#608Medium

Tree Node

Database

Acceptance: 73.1%

#609Medium

Find Duplicate File in System

ArrayHash TableString

Acceptance: 67.6%

#611Medium

Valid Triangle Number

ArrayBinary SearchGreedy+2

Acceptance: 56.8%

#612Medium

Shortest Distance in a Plane

Database

Acceptance: 61.3%

Page 7 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