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

Second Degree Follower

Database

Acceptance: 39.3%

#616Medium

Add Bold Tag in String

ArrayHash TableString+2

Acceptance: 51.4%

#621Medium

Task Scheduler

ArrayCountingGreedy+3

Acceptance: 63.4%

#622Medium

Design Circular Queue

ArrayDesignLinked List+1

Acceptance: 55.4%

#623Medium

Add One Row to Tree

Binary TreeBreadth-First SearchDepth-First Search+1

Acceptance: 64.1%

#624Medium

Maximum Distance in Arrays

ArrayGreedy

Acceptance: 45.7%

#625Medium

Minimum Factorization

GreedyMath

Acceptance: 34.2%

#626Medium

Exchange Seats

Database

Acceptance: 71.6%

#633Medium

Sum of Square Numbers

Binary SearchMathTwo Pointers

Acceptance: 37.0%

#634Medium

Find the Derangement of An Array

Dynamic ProgrammingMath

Acceptance: 41.9%

#635Medium

Design Log Storage System

DesignHash TableOrdered Set+1

Acceptance: 59.8%

#636Medium

Exclusive Time of Functions

ArrayStack

Acceptance: 66.2%

#638Medium

Shopping Offers

ArrayBacktrackingBit Manipulation+3

Acceptance: 52.3%

#640Medium

Solve the Equation

MathSimulationString

Acceptance: 46.7%

#641Medium

Design Circular Deque

ArrayDesignLinked List+1

Acceptance: 64.6%

#646Medium

Maximum Length of Pair Chain

ArrayDynamic ProgrammingGreedy+1

Acceptance: 62.2%

#647Medium

Palindromic Substrings

Dynamic ProgrammingStringTwo Pointers

Acceptance: 73.2%

#648Medium

Replace Words

ArrayHash TableString+1

Acceptance: 68.7%

#649Medium

Dota2 Senate

GreedyQueueString

Acceptance: 50.3%

#650Medium

2 Keys Keyboard

Dynamic ProgrammingMath

Acceptance: 59.6%

#651Medium

4 Keys Keyboard

Dynamic ProgrammingMath

Acceptance: 56.5%

#652Medium

Find Duplicate Subtrees

Binary TreeDepth-First SearchHash Table+1

Acceptance: 60.6%

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

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

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

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

#669Medium

Trim a Binary Search Tree

Binary Search TreeBinary TreeDepth-First Search+1

Acceptance: 66.9%

#670Medium

Maximum Swap

GreedyMath

Acceptance: 51.6%

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

#681Medium

Next Closest Time

BacktrackingEnumerationHash Table+1

Acceptance: 46.8%

#684Medium

Redundant Connection

Breadth-First SearchDepth-First SearchGraph+1

Acceptance: 68.0%

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

#690Medium

Employee Importance

ArrayBreadth-First SearchDepth-First Search+2

Acceptance: 69.4%

#692Medium

Top K Frequent Words

Bucket SortCountingHash Table+4

Acceptance: 60.6%

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

#698Medium

Partition to K Equal Sum Subsets

ArrayBacktrackingBit Manipulation+3

Acceptance: 38.6%

#701Medium

Insert into a Binary Search Tree

Binary Search TreeBinary TreeTree

Acceptance: 73.6%

#702Medium

Search in a Sorted Array of Unknown Size

ArrayBinary SearchInteractive

Acceptance: 73.1%

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