Combinatorics LeetCode Problems: All 32, With Python Solutions

Every problem in this library that LeetCode tags Combinatorics 32 in total, 27 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 32 problems
  • 2 Easy
  • 13 Medium
  • 17 Hard

How Combinatorics problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Combinatorics problems — each one explains the approach, gives a Python template and states its complexity.

  • Math and Number Theory — Find the closed form, the invariant, or the modular identity — and skip the loop entirely.

Combinatorics problems by difficulty

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

Easy (2)

#ProblemDifficultyTopics
1863Sum of All Subset XOR TotalsEasyBit Manipulation, Array, Math +3
2928Distribute Candies Among Children IEasyMath, Combinatorics, Enumeration

Medium (13)

#ProblemDifficultyTopics
62Unique PathsMediumMath, Dynamic Programming, Combinatorics
1201Ugly Number IIIMediumMath, Binary Search, Combinatorics +1
1621Number of Sets of K Non-Overlapping Line SegmentsMediumMath, Dynamic Programming, Combinatorics
1641Count Sorted Vowel StringsMediumMath, Dynamic Programming, Combinatorics
2063Vowels of All SubstringsMediumMath, String, Dynamic Programming +1
2221Find Triangular Sum of an ArrayMediumArray, Math, Combinatorics +1
2400Number of Ways to Reach a Position After Exactly k StepsMediumMath, Dynamic Programming, Combinatorics
2597The Number of Beautiful SubsetsMediumArray, Hash Table, Math +4
2929Distribute Candies Among Children IIMediumMath, Combinatorics, Enumeration
2930Number of Strings Which Can Be Rearranged to Contain SubstringMediumMath, Dynamic Programming, Combinatorics
634Find the Derangement of An ArrayPremiumMediumMath, Dynamic Programming, Combinatorics
2539Count the Number of Good SubsequencesPremiumMediumHash Table, Math, String +2
2638Count the Number of K-Free SubsetsPremiumMediumArray, Math, Dynamic Programming +2

Hard (17)

#ProblemDifficultyTopics
458Poor PigsHardMath, Dynamic Programming, Combinatorics
920Number of Music PlaylistsHardMath, Dynamic Programming, Combinatorics
1359Count All Valid Pickup and Delivery OptionsHardMath, Dynamic Programming, Combinatorics
1467Probability of a Two Boxes Having The Same Number of Distinct BallsHardArray, Math, Dynamic Programming +3
1569Number of Ways to Reorder Array to Get Same BSTHardTree, Union Find, Binary Search Tree +7
1643Kth Smallest InstructionsHardArray, Math, Dynamic Programming +1
1735Count Ways to Make Array With ProductHardArray, Math, Dynamic Programming +2
1830Minimum Number of Operations to Make String SortedHardMath, String, Combinatorics
1866Number of Ways to Rearrange Sticks With K Sticks VisibleHardMath, Dynamic Programming, Combinatorics
1916Count Ways to Build Rooms in an Ant ColonyHardTree, Graph, Topological Sort +3
2338Count the Number of Ideal ArraysHardMath, Dynamic Programming, Combinatorics +1
2514Count AnagramsHardHash Table, Math, String +2
2842Count K-Subsequences of a String With Maximum BeautyHardGreedy, Hash Table, Math +2
2954Count the Number of Infection SequencesHardArray, Math, Combinatorics
2963Count the Number of Good PartitionsHardArray, Hash Table, Math +1
2912Number of Ways to Reach Destination in the GridPremiumHardMath, Dynamic Programming, Combinatorics
2927Distribute Candies Among Children IIIPremiumHardMath, Combinatorics

When the Combinatorics 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.