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

4 Keys Keyboard

Dynamic ProgrammingMath

Acceptance: 56.5%

#652Medium

Find Duplicate Subtrees

Binary TreeDepth-First SearchHash Table+1

Acceptance: 60.6%

#653Easy

Two Sum IV - Input is a BST

Binary Search TreeBinary TreeBreadth-First Search+4

Acceptance: 63.7%

#654Medium

Maximum Binary Tree

ArrayBinary TreeDivide and Conquer+3

Acceptance: 86.3%

#655Medium

Print Binary Tree

Binary TreeBreadth-First SearchDepth-First Search+1

Acceptance: 66.5%

#656Hard

Coin Path

ArrayDynamic Programming

Acceptance: 34.2%

#657Easy

Robot Return to Origin

SimulationString

Acceptance: 78.0%

#658Medium

Find K Closest Elements

ArrayBinary SearchHeap (Priority Queue)+3

Acceptance: 50.1%

#659Medium

Split Array into Consecutive Subsequences

ArrayGreedyHash Table+1

Acceptance: 52.1%

#660Hard

Remove 9

Math

Acceptance: 57.3%

#661Easy

Image Smoother

ArrayMatrix

Acceptance: 69.8%

#662Medium

Maximum Width of Binary Tree

Binary TreeBreadth-First SearchDepth-First Search+1

Acceptance: 46.0%

#663Medium

Equal Tree Partition

Binary TreeDepth-First SearchTree

Acceptance: 42.3%

#664Hard

Strange Printer

Dynamic ProgrammingString

Acceptance: 61.0%

#665Medium

Non-decreasing Array

Array

Acceptance: 25.5%

#666Medium

Path Sum IV

ArrayBinary TreeDepth-First Search+2

Acceptance: 62.5%

#667Medium

Beautiful Arrangement II

ArrayMath

Acceptance: 61.1%

#668Hard

Kth Smallest Number in Multiplication Table

Binary SearchMath

Acceptance: 54.5%

#669Medium

Trim a Binary Search Tree

Binary Search TreeBinary TreeDepth-First Search+1

Acceptance: 66.9%

#670Medium

Maximum Swap

GreedyMath

Acceptance: 51.6%

#671Easy

Second Minimum Node In a Binary Tree

Binary TreeDepth-First SearchTree

Acceptance: 46.0%

#672Medium

Bulb Switcher II

Bit ManipulationBreadth-First SearchDepth-First Search+1

Acceptance: 50.6%

#673Medium

Number of Longest Increasing Subsequence

ArrayBinary Indexed TreeDynamic Programming+1

Acceptance: 52.2%

#674Easy

Longest Continuous Increasing Subsequence

Array

Acceptance: 51.9%

#675Hard

Cut Off Trees for Golf Event

ArrayBreadth-First SearchHeap (Priority Queue)+1

Acceptance: 36.8%

#676Medium

Implement Magic Dictionary

Depth-First SearchDesignHash Table+2

Acceptance: 57.8%

#677Medium

Map Sum Pairs

DesignHash TableString+1

Acceptance: 57.4%

#678Medium

Valid Parenthesis String

Dynamic ProgrammingGreedyStack+1

Acceptance: 40.5%

#679Hard

24 Game

ArrayBacktrackingMath

Acceptance: 59.4%

#680Easy

Valid Palindrome II

GreedyStringTwo Pointers

Acceptance: 44.7%

#681Medium

Next Closest Time

BacktrackingEnumerationHash Table+1

Acceptance: 46.8%

#682Easy

Baseball Game

ArraySimulationStack

Acceptance: 80.8%

#683Hard

K Empty Slots

ArrayBinary Indexed TreeHeap (Priority Queue)+5

Acceptance: 38.0%

#684Medium

Redundant Connection

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 68.0%

#685Hard

Redundant Connection II

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 36.6%

#686Medium

Repeated String Match

StringString Matching

Acceptance: 39.7%

#687Medium

Longest Univalue Path

Binary TreeDepth-First SearchTree

Acceptance: 44.3%

#688Medium

Knight Probability in Chessboard

Dynamic Programming

Acceptance: 57.0%

#689Hard

Maximum Sum of 3 Non-Overlapping Subarrays

ArrayDynamic Programming

Acceptance: 59.8%

#690Medium

Employee Importance

ArrayBreadth-First SearchDepth-First Search+2

Acceptance: 69.4%

#691Hard

Stickers to Spell Word

ArrayBacktrackingBit Manipulation+3

Acceptance: 50.7%

#692Medium

Top K Frequent Words

Bucket SortCountingHash Table+4

Acceptance: 60.6%

#693Easy

Binary Number with Alternating Bits

Bit Manipulation

Acceptance: 69.8%

#694Medium

Number of Distinct Islands

Breadth-First SearchDepth-First SearchHash Function+2

Acceptance: 62.8%

#695Medium

Max Area of Island

ArrayBreadth-First SearchDepth-First Search+2

Acceptance: 73.9%

#696Easy

Count Binary Substrings

StringTwo Pointers

Acceptance: 70.3%

#697Easy

Degree of an Array

ArrayHash Table

Acceptance: 58.2%

#698Medium

Partition to K Equal Sum Subsets

ArrayBacktrackingBit Manipulation+3

Acceptance: 38.6%

#699Hard

Falling Squares

ArrayOrdered SetSegment Tree

Acceptance: 48.3%

#700Easy

Search in a Binary Search Tree

Binary Search TreeBinary TreeTree

Acceptance: 83.1%

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