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

Max Increase to Keep City Skyline

ArrayGreedyMatrix

Acceptance: 86.2%

#808Medium

Soup Servings

Dynamic ProgrammingMathProbability and Statistics

Acceptance: 59.7%

#809Medium

Expressive Words

ArrayStringTwo Pointers

Acceptance: 46.8%

#811Medium

Subdomain Visit Count

ArrayCountingHash Table+1

Acceptance: 77.2%

#813Medium

Largest Sum of Averages

ArrayDynamic ProgrammingPrefix Sum

Acceptance: 55.5%

#814Medium

Binary Tree Pruning

Binary TreeDepth-First SearchTree

Acceptance: 72.3%

#816Medium

Ambiguous Coordinates

BacktrackingEnumerationString

Acceptance: 56.4%

#817Medium

Linked List Components

ArrayHash TableLinked List

Acceptance: 57.8%

#820Medium

Short Encoding of Words

ArrayHash TableString+1

Acceptance: 61.0%

#822Medium

Card Flipping Game

ArrayHash Table

Acceptance: 50.7%

#823Medium

Binary Trees With Factors

ArrayDynamic ProgrammingHash Table+1

Acceptance: 52.9%

#825Medium

Friends Of Appropriate Ages

ArrayBinary SearchSorting+1

Acceptance: 49.9%

#826Medium

Most Profit Assigning Work

ArrayBinary SearchGreedy+2

Acceptance: 56.4%

#831Medium

Masking Personal Information

String

Acceptance: 56.2%

#833Medium

Find And Replace in String

ArrayHash TableSorting+1

Acceptance: 50.9%

#835Medium

Image Overlap

ArrayMatrix

Acceptance: 70.6%

#837Medium

New 21 Game

Dynamic ProgrammingMathProbability and Statistics+1

Acceptance: 52.0%

#838Medium

Push Dominoes

Dynamic ProgrammingStringTwo Pointers

Acceptance: 63.0%

#840Medium

Magic Squares In Grid

ArrayHash TableMath+1

Acceptance: 55.1%

#841Medium

Keys and Rooms

Breadth-First SearchDepth-First SearchGraph

Acceptance: 76.2%

#842Medium

Split Array into Fibonacci Sequence

BacktrackingString

Acceptance: 40.3%

#845Medium

Longest Mountain in Array

ArrayDynamic ProgrammingEnumeration+1

Acceptance: 42.0%

#846Medium

Hand of Straights

ArrayGreedyHash Table+1

Acceptance: 57.9%

#848Medium

Shifting Letters

ArrayPrefix SumString

Acceptance: 46.1%

#849Medium

Maximize Distance to Closest Person

Array

Acceptance: 49.7%

#851Medium

Loud and Rich

ArrayDepth-First SearchGraph+1

Acceptance: 63.9%

#852Medium

Peak Index in a Mountain Array

ArrayBinary Search

Acceptance: 66.9%

#853Medium

Car Fleet

ArrayMonotonic StackSorting+1

Acceptance: 55.5%

#855Medium

Exam Room

DesignHeap (Priority Queue)Ordered Set

Acceptance: 43.6%

#856Medium

Score of Parentheses

StackString

Acceptance: 63.9%

#858Medium

Mirror Reflection

GeometryMathNumber Theory

Acceptance: 62.3%

#861Medium

Score After Flipping Matrix

ArrayBit ManipulationGreedy+1

Acceptance: 80.3%

#863Medium

All Nodes Distance K in Binary Tree

Binary TreeBreadth-First SearchDepth-First Search+2

Acceptance: 68.1%

#865Medium

Smallest Subtree with all the Deepest Nodes

Binary TreeBreadth-First SearchDepth-First Search+2

Acceptance: 77.5%

#866Medium

Prime Palindrome

MathNumber Theory

Acceptance: 28.6%

#869Medium

Reordered Power of 2

CountingEnumerationHash Table+2

Acceptance: 66.0%

#870Medium

Advantage Shuffle

ArrayGreedySorting+1

Acceptance: 55.0%

#873Medium

Length of Longest Fibonacci Subsequence

ArrayDynamic ProgrammingHash Table

Acceptance: 57.5%

#874Medium

Walking Robot Simulation

ArrayHash TableSimulation

Acceptance: 64.5%

#875Medium

Koko Eating Bananas

ArrayBinary Search

Acceptance: 50.4%

#877Medium

Stone Game

ArrayDynamic ProgrammingGame Theory+1

Acceptance: 77.0%

#880Medium

Decoded String at Index

StackString

Acceptance: 37.3%

#881Medium

Boats to Save People

ArrayGreedySorting+1

Acceptance: 62.1%

#885Medium

Spiral Matrix III

ArrayMatrixSimulation

Acceptance: 84.6%

#886Medium

Possible Bipartition

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 53.0%

#889Medium

Construct Binary Tree from Preorder and Postorder Traversal

ArrayBinary TreeDivide and Conquer+2

Acceptance: 78.0%

#890Medium

Find and Replace Pattern

ArrayHash TableString

Acceptance: 76.8%

#893Medium

Groups of Special-Equivalent Strings

ArrayHash TableSorting+1

Acceptance: 73.5%

#894Medium

All Possible Full Binary Trees

Binary TreeDynamic ProgrammingMemoization+2

Acceptance: 82.8%

#898Medium

Bitwise ORs of Subarrays

ArrayBit ManipulationDynamic Programming

Acceptance: 56.8%

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