← All templates

Backtracking

Pro

Backtracking is essentially brute force and should be used only when we need to generate all solutions. It should only be used when more efficient approaches such as greedy algorithms and dynamic programming cannot be used.

Keywords for identifying Backtracking Problems

β†’ Find all possible …
β†’ Find any such that …
β†’ Count total number that …
β†’ Determine if a solution exists …
β†’ Find the best solution to …
β†’ Permutation/Combination problem …

Unlock the Backtracking template

Get the full code template and worked LeetCode examples for Backtracking β€” plus every other pattern in the library β€” with a one-time $29 lifetime upgrade.

Upgrade to ProSee free Binary Search template β†’
Backtracking Β· Templates Β· Grind Patterns