Practise Problems for Backtracking
1. Maze problem: http://interviewrack.blogspot.in/2017/03/maze-problem-backtracking.html
2. Search for words in matrix:
3. Permutations:
4. Sudoku:
Given a partially filled 9×9 2D array ‘grid[9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9.
5. The Word Break Problem:
Given an string and a dictionary of words, find out if the input string can be broken into a space-separated sequence of one or more dictionary words.
6. N Queens Problem
In chess, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chessboard has 8 rows and 8 columns.
The standard 8 by 8 Queen’s problem asks how to place 8 queens on an ordinary chessboard so that none of them can attack any other in one move.
(A queen attacks another queen if the two are in the same row, column, or diagonal)
7. Landmines:
Given a path in the form of a rectangular matrix having few landmines arbitrarily placed (marked as 0), calculate length of the shortest safe route possible from any cell in the first column to any cell in the last column of the matrix.
We have to avoid landmines and their four adjacent cells (left, right, above and below) as they are also unsafe.
We are allowed to move to only adjacent cells which are not landmines. i.e. the route cannot contains any diagonal moves.
Comments
Post a Comment