InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Level 5

Backtracking

Backtracking is the method of building the solution one piece at a time recursively and incrementally. The method keeps removing all those bits that do not contribute to the solution.

One such real-life example is a maze. At every dead end, you trace back your steps and set out for another path- thus setting a perfect example for backtracking. Similarly, Sudoku works on the same principle.

That’s what backtracking is, retracing back the steps and discarding the choice that doesn't add on to build the correct solution.

Backtracking

Important Tutorials

1. Recursion Basics Using Factorial
View Tutorial
2. Complexity Analysis Of Recursive Programs
View Tutorial
3. Why Recursion Is Not Always Good
View Tutorial
4. Time Complexity Analysis Of Recursion
View Tutorial
5. Space Complexity Analysis Of Recursion
View Tutorial
6. Backtracking
View Tutorial
7. Backtracking Pseudocode
View Tutorial

Backtracking Problems

Subsets
Problem Score Companies Time Status
Subset 250 61:48
Combinations 300 45:36
Combination Sum 300 61:17
Combination Sum II 300 40:44
Subsets II 300 39:44
Bruteforce builder
Problem Score Companies Time Status
Letter Phone 250 52:57
Palindrome Partitioning 300 66:14
Generate all Parentheses II 350
51:39
Permutations
Problem Score Companies Time Status
Permutations 350 39:18
Maths and backtracking
Problem Score Companies Time Status
Gray Code 350
56:54
Kth Permutation Sequence 350 71:20
Game solving
Problem Score Companies Time Status
NQueens 550 72:38
Sudoku 700 66:28

Additional Practice

Problem Score Companies Time Status
Maximal String 200
42:44