Divide and Conquer LeetCode Problems: All 47, With Python Solutions

Every problem in this library that LeetCode tags Divide and Conquer 47 in total, 41 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 47 problems
  • 5 Easy
  • 26 Medium
  • 16 Hard

Divide and Conquer problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (5)

#ProblemDifficultyTopics
108Convert Sorted Array to Binary Search TreeEasyTree, Binary Search Tree, Array +2
169Majority ElementEasyArray, Hash Table, Divide and Conquer +2
190Reverse BitsEasyBit Manipulation, Divide and Conquer
191Number of 1 BitsEasyBit Manipulation, Divide and Conquer
1763Longest Nice SubstringEasyBit Manipulation, Hash Table, String +2

Medium (26)

#ProblemDifficultyTopics
53Maximum SubarrayMediumArray, Divide and Conquer, Dynamic Programming
105Construct Binary Tree from Preorder and Inorder TraversalMediumTree, Array, Hash Table +2
106Construct Binary Tree from Inorder and Postorder TraversalMediumTree, Array, Hash Table +2
109Convert Sorted List to Binary Search TreeMediumTree, Binary Search Tree, Linked List +2
148Sort ListMediumLinked List, Two Pointers, Divide and Conquer +2
215Kth Largest Element in an ArrayMediumArray, Divide and Conquer, Quickselect +2
240Search a 2D Matrix IIMediumArray, Binary Search, Divide and Conquer +1
307Range Sum Query - MutableMediumDesign, Binary Indexed Tree, Segment Tree +2
324Wiggle Sort IIMediumGreedy, Array, Divide and Conquer +2
347Top K Frequent ElementsMediumArray, Hash Table, Divide and Conquer +5
372Super PowMediumMath, Divide and Conquer
395Longest Substring with At Least K Repeating CharactersMediumHash Table, String, Divide and Conquer +1
427Construct Quad TreeMediumTree, Array, Divide and Conquer +1
558Logical OR of Two Binary Grids Represented as Quad-TreesMediumTree, Divide and Conquer
654Maximum Binary TreeMediumStack, Tree, Array +3
889Construct Binary Tree from Preorder and Postorder TraversalMediumTree, Array, Hash Table +2
912Sort an ArrayMediumArray, Divide and Conquer, Bucket Sort +5
918Maximum Sum Circular SubarrayMediumQueue, Array, Divide and Conquer +2
932Beautiful ArrayMediumArray, Math, Divide and Conquer
973K Closest Points to OriginMediumGeometry, Array, Math +4
1382Balance a Binary Search TreeMediumGreedy, Tree, Depth-First Search +3
1738Find Kth Largest XOR Coordinate ValueMediumBit Manipulation, Array, Divide and Conquer +5
1985Find the Kth Largest Integer in the ArrayMediumArray, String, Divide and Conquer +3
2343Query Kth Smallest Trimmed NumberMediumArray, String, Divide and Conquer +4
1756Design Most Recently Used QueuePremiumMediumDesign, Array, Linked List +3
2031Count Subarrays With More Ones Than ZerosPremiumMediumBinary Indexed Tree, Segment Tree, Array +5

Hard (16)

#ProblemDifficultyTopics
4Median of Two Sorted ArraysHardArray, Binary Search, Divide and Conquer
23Merge k Sorted ListsHardLinked List, Divide and Conquer, Heap (Priority Queue) +1
218The Skyline ProblemHardBinary Indexed Tree, Segment Tree, Array +5
315Count of Smaller Numbers After SelfHardBinary Indexed Tree, Segment Tree, Array +4
327Count of Range SumHardBinary Indexed Tree, Segment Tree, Array +4
493Reverse PairsHardBinary Indexed Tree, Segment Tree, Array +4
1569Number of Ways to Reorder Array to Get Same BSTHardTree, Union Find, Binary Search Tree +7
1649Create Sorted Array through InstructionsHardBinary Indexed Tree, Segment Tree, Array +4
1982Find Array Given Subset SumsHardArray, Divide and Conquer
2179Count Good Triplets in an ArrayHardBinary Indexed Tree, Segment Tree, Array +4
2407Longest Increasing Subsequence IIHardBinary Indexed Tree, Segment Tree, Queue +4
2426Number of Pairs Satisfying InequalityHardBinary Indexed Tree, Segment Tree, Array +4
1274Number of Ships in a RectanglePremiumHardArray, Divide and Conquer, Interactive
2519Count the Number of K-Big IndicesPremiumHardBinary Indexed Tree, Segment Tree, Array +4
2613Beautiful PairsPremiumHardGeometry, Array, Math +3
2792Count Nodes That Are Great EnoughPremiumHardTree, Depth-First Search, Divide and Conquer +1

When the Divide and Conquer problem arrives live

Stealth Interview is a desktop app for macOS and Windows. It reads the coding 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 is saying — while staying invisible to screen sharing.