Hard LeetCode Problems: All 661,
With Python Solutions

Hard problems usually combine two techniques, or need a non-obvious invariant before any technique applies at all. They are worth studying for the ideas rather than for the odds of being asked one.

The rating is LeetCode's own, carried through unchanged.

With a full solution
505
LeetCode Premium
137
Patterns
22

Eyes only

A hard problem, live, with someone watching.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Page 1 of 4

Hard problems

Showing the first 200 of 661 problems. Problems with a complete Python solution are listed first, then by ascending problem number.

Hard problems
No.Problem
0004Median of Two Sorted Arrays
0010Regular Expression Matching
0023Merge k Sorted Lists
0025Reverse Nodes in k-Group
0030Substring with Concatenation of All Words
0032Longest Valid Parentheses
0037Sudoku Solver
0041First Missing Positive
0042Trapping Rain Water
0044Wildcard Matching
0051N-Queens
0052N-Queens II
0060Permutation Sequence
0065Valid Number
0068Text Justification
0076Minimum Window Substring
0084Largest Rectangle in Histogram
0085Maximal Rectangle
0087Scramble String
0115Distinct Subsequences
0123Best Time to Buy and Sell Stock III
0124Binary Tree Maximum Path Sum
0126Word Ladder II
0127Word Ladder
0132Palindrome Partitioning II
0135Candy
0140Word Break II
0149Max Points on a Line
0154Find Minimum in Rotated Sorted Array II
0174Dungeon Game
0185Department Top Three Salaries
0188Best Time to Buy and Sell Stock IV
0212Word Search II
0214Shortest Palindrome
0218The Skyline Problem
0220Contains Duplicate III
0224Basic Calculator
0233Number of Digit One
0239Sliding Window Maximum
0262Trips and Users
0273Integer to English Words
0282Expression Add Operators
0295Find Median from Data Stream
0297Serialize and Deserialize Binary Tree
0301Remove Invalid Parentheses
0312Burst Balloons
0315Count of Smaller Numbers After Self
0321Create Maximum Number
0327Count of Range Sum
0329Longest Increasing Path in a Matrix
0330Patching Array
0332Reconstruct Itinerary
0335Self Crossing
0336Palindrome Pairs
0352Data Stream as Disjoint Intervals
0354Russian Doll Envelopes
0363Max Sum of Rectangle No Larger Than K
0381Insert Delete GetRandom O(1) - Duplicates allowed
0391Perfect Rectangle
0403Frog Jump
0407Trapping Rain Water II
0410Split Array Largest Sum
0420Strong Password Checker
0432All O`one Data Structure
0440K-th Smallest in Lexicographical Order
0446Arithmetic Slices II - Subsequence
0458Poor Pigs
0460LFU Cache
0466Count The Repetitions
0472Concatenated Words
0479Largest Palindrome Product
0480Sliding Window Median
0483Smallest Good Base
0488Zuma Game
0493Reverse Pairs
0502IPO
0514Freedom Trail
0517Super Washing Machines
0546Remove Boxes
0552Student Attendance Record II
0564Find the Closest Palindrome
0587Erect the Fence
0591Tag Validator
0600Non-negative Integers without Consecutive Ones
0601Human Traffic of Stadium
0629K Inverse Pairs Array
0630Course Schedule III
0632Smallest Range Covering Elements from K Lists
0639Decode Ways II
0664Strange Printer
0668Kth Smallest Number in Multiplication Table
0675Cut Off Trees for Golf Event
067924 Game
0685Redundant Connection II
0689Maximum Sum of 3 Non-Overlapping Subarrays
0691Stickers to Spell Word
0699Falling Squares
0710Random Pick with Blacklist
0715Range Module
0719Find K-th Smallest Pair Distance
0730Count Different Palindromic Subsequences
0732My Calendar III
0736Parse Lisp Expression
0741Cherry Pickup
0745Prefix and Suffix Search
0749Contain Virus
0753Cracking the Safe
0757Set Intersection Size At Least Two
0761Special Binary String
0765Couples Holding Hands
0768Max Chunks To Make Sorted II
0773Sliding Puzzle
0778Swim in Rising Water
0780Reaching Points
0782Transform to Chessboard
0793Preimage Size of Factorial Zeroes Function
0798Smallest Rotation with Highest Score
0801Minimum Swaps To Make Sequences Increasing
0803Bricks Falling When Hit
0805Split Array With Same Average
0810Chalkboard XOR Game
0815Bus Routes
0818Race Car
0827Making A Large Island
0828Count Unique Characters of All Substrings of a Given String
0829Consecutive Numbers Sum
0834Sum of Distances in Tree
0839Similar String Groups
0847Shortest Path Visiting All Nodes
0850Rectangle Area II
0854K-Similar Strings
0857Minimum Cost to Hire K Workers
0862Shortest Subarray with Sum at Least K
0864Shortest Path to Get All Keys
0871Minimum Number of Refueling Stops
0878Nth Magical Number
0879Profitable Schemes
0882Reachable Nodes In Subdivided Graph
0887Super Egg Drop
0891Sum of Subsequence Widths
0895Maximum Frequency Stack
0899Orderly Queue
0902Numbers At Most N Given Digit Set
0903Valid Permutations for DI Sequence
0906Super Palindromes
0913Cat and Mouse
0920Number of Music Playlists
0924Minimize Malware Spread
0927Three Equal Parts
0928Minimize Malware Spread II
0936Stamping The Sequence
0940Distinct Subsequences II
0943Find the Shortest Superstring
0952Largest Component Size by Common Factor
0956Tallest Billboard
0960Delete Columns to Make Sorted III
0964Least Operators to Express Number
0968Binary Tree Cameras
0975Odd Even Jump
0980Unique Paths III
0982Triples with Bitwise AND Equal To Zero
0987Vertical Order Traversal of a Binary Tree
0992Subarrays with K Different Integers
0995Minimum Number of K Consecutive Bit Flips
0996Number of Squareful Arrays
1000Minimum Cost to Merge Stones
1001Grid Illumination
1012Numbers With Repeated Digits
1028Recover a Tree From Preorder Traversal
1032Stream of Characters
1036Escape a Large Maze
1044Longest Duplicate Substring
1074Number of Submatrices That Sum to Target
1092Shortest Common Supersequence
1095Find in Mountain Array
1096Brace Expansion II
1106Parsing A Boolean Expression
1125Smallest Sufficient Team
1147Longest Chunked Palindrome Decomposition
1157Online Majority Element In Subarray
1163Last Substring in Lexicographical Order
1172Dinner Plate Stacks
1178Number of Valid Words for Each Puzzle
1187Make Array Strictly Increasing
1192Critical Connections in a Network
1203Sort Items by Groups Respecting Dependencies
1206Design Skiplist
1210Minimum Moves to Reach Target with Rotations
1220Count Vowels Permutation
1223Dice Roll Simulation
1224Maximum Equal Frequency
1235Maximum Profit in Job Scheduling
1240Tiling a Rectangle with the Fewest Squares
1250Check If It Is a Good Array
1255Maximum Score Words Formed by Letters
1263Minimum Moves to Move a Box to Their Target Location
1269Number of Ways to Stay in the Same Place After Some Steps
1278Palindrome Partitioning III
1284Minimum Number of Flips to Convert Binary Matrix to Zero Matrix
1289Minimum Falling Path Sum II