pyPython Practice LabFrom first print to final round
TOPIC 13 OF 18

Recursion and Backtracking Python practice problems

Base cases, call stacks, recursive structure, choice trees, pruning, and undoing choices safely.

24 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Compute factorial recursivelySum digits recursivelyCalculate integer power recursivelyFind GCD recursivelyBinary search recursivelyCheck a palindrome recursivelyGenerate all permutationsGenerate all subsets
REUSABLE THINKING

Problem-solving patterns

  • recursion · base case
  • recursion · digits
  • divide and conquer · power
  • Euclid · recursion
  • binary search · recursion
PRACTICE OUTCOME

What this topic builds

Learn the idea once, use it across the exercises, and explain why your approach works.

ORDERED PRACTICE

All 24 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #219
    Compute factorial recursively: Recursive arrangement count

    Use recursion to calculate seven factorial.

    BeginnerPremium
  2. #220
    Compute factorial recursively: Recursive base case

    Verify that the base case returns one for zero.

    BeginnerPremium
  3. #221
    Sum digits recursively: Checksum

    Calculate a simple digit checksum recursively.

    IntermediatePremium
  4. #222
    Sum digits recursively: Negative input

    Ignore the sign before summing a negative number's digits.

    IntermediatePremium
  5. #223
    Calculate integer power recursively: Large exponent efficiently

    Compute a power using logarithmic recursion.

    IntermediatePremium
  6. #224
    Calculate integer power recursively: Zero exponent

    Any nonzero base raised to zero returns one.

    IntermediatePremium
  7. #225
    Find GCD recursively: Shared factor

    Find the greatest common divisor of two related values.

    IntermediatePremium
  8. #226
    Find GCD recursively: Second input zero

    The base case returns the first value immediately.

    AdvancedPremium
  9. #227
    Binary search recursively: Found target

    Find the zero-based index of a target in a sorted catalog.

    AdvancedPremium
  10. #228
    Binary search recursively: Missing target

    Return -1 after the search range becomes empty.

    AdvancedPremium
  11. #229
    Check a palindrome recursively: Odd-length palindrome

    Verify a word with one middle character.

    AdvancedPremium
  12. #230
    Check a palindrome recursively: Early mismatch

    Stop and return False as soon as outer characters differ.

    AdvancedPremium
  13. #231
    Generate all permutations: Three-character arrangements

    List every ordering of three distinct task labels.

    AdvancedPremium
  14. #232
    Generate all permutations: Two-character arrangements

    Show the smallest nontrivial permutation set.

    AdvancedPremium
  15. #233
    Generate all subsets: Feature subsets

    List every subset of three numbered features.

    Interview-LevelPremium
  16. #234
    Generate all subsets: Single value

    A one-value set has the empty subset and one nonempty subset.

    Interview-LevelPremium
  17. #235
    Generate balanced parentheses: Three pairs

    Generate every valid expression containing three pairs.

    Interview-LevelPremium
  18. #236
    Generate balanced parentheses: One pair

    Generate the single valid expression for one pair.

    Interview-LevelPremium
  19. #237
    Count N-Queens solutions: Classic four-queen board

    Count valid arrangements on a 4-by-4 chessboard.

    Interview-LevelPremium
  20. #238
    Count N-Queens solutions: Five-queen board

    Count solutions for the next board size to exercise more branches.

    Interview-LevelPremium
  21. #239
    Sort with merge sort: General list

    Apply a stable divide-and-conquer sort to mixed integers.

    Interview-LevelPremium
  22. #240
    Sort with merge sort: Duplicates and negatives

    Preserve duplicates while ordering signed values.

    Interview-LevelPremium
  23. #241
    Sort with quicksort: Quicksort practice

    Sort a general list using recursive partitioning.

    Interview-LevelPremium
  24. #242
    Sort with quicksort: Many duplicate pivots

    Use the equal partition to group repeated values efficiently.

    Interview-LevelPremium