Skip to content
Optimal Lab

Practice · 10 problems

Backtracking

0 of 10 solved on this device

Watch it first · interactiveBacktracking: choose, explore, undo →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 040SubsetsGiven an integer array `nums` of unique elements, return all possible subsets (the power set). The solution must not contain duplicate subsets; any order is fine.Medium
  2. 041PermutationsGiven an array `nums` of distinct integers, return all possible permutations in any order.Medium
  3. 042N-QueensPlace `n` queens on an n x n chessboard so that no two attack each other. Return all distinct solutions, each as a list of strings where 'Q' is a queen and '.' is empty.Hard
  4. 081Generate ParenthesesGiven `n` pairs of parentheses, generate all combinations of well-formed parentheses.Medium
  5. 082Combination SumGiven an array of DISTINCT integers `candidates` and a `target`, return all unique combinations summing to target. Each candidate may be used unlimited times. Two combinations are the same if they contain the same numbers with the same counts.Medium
  6. 083Word SearchGiven an m x n grid of characters and a string `word`, return true if the word can be built from sequentially adjacent cells (horizontal or vertical neighbors). The same cell may not be used more than once.Medium
  7. 084Letter Combinations of a Phone NumberGiven a string of digits 2-9, return all letter combinations the number could spell, using the standard telephone keypad mapping. Any order is acceptable.Medium
  8. 124Subsets IIGiven an integer array `nums` that MAY CONTAIN DUPLICATES, return all possible subsets without any duplicate subsets. Any order is acceptable.Medium
  9. 125Combination Sum IIGiven a collection `candidates` that may contain duplicates and a `target`, find all unique combinations summing to target. Each candidate may be used AT MOST ONCE.Medium
  10. 126Palindrome PartitioningGiven a string `s`, partition it so every substring in the partition is a palindrome. Return all possible palindrome partitionings.Medium