Lesson overview · Free interview practice

Backtracking

Find solutions by exploring all possible options and backtracking.

Topics in the full lesson
  • Concept and Use Cases
  • Key Concepts
  • Time and Space Complexity
  • Backtracking Operations and Methods
  • Practical Tips and Tricks
  • Common Gotchas
  • Advanced Topics
  • Interview Tips and Tricks
  • Common Mistakes

Try the free interview questions

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

CodingMedium

Combination Sum

Question

Given an array of distinct positive integers candidates and a target integer target, return all unique combinations of candidates whose sum equals target. You may use the same number any number of times.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingHard

N-Queens

Question

The N-Queens puzzle places n queens on an n x n chessboard so that no two queens share a row, column, or diagonal. Given n, return all distinct solutions; each solution is the board drawn with 'Q' marking a queen and '.' marking an empty square.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingHard

Sudoku Solver

Question

Design an algorithm to solve a Sudoku puzzle, which is a 9x9 grid filled with numbers from 1-9, where each row, column, and 3x3 sub-grid must contain each number only once.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Backtracking material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium