## Profile

###### About

## Zombie Clusters Hackerrank Solution

__Download __

Recursive Backtracking Algorithm: Successor Backtracking Given a board, which represents a number of non-empty subarrays. One solution is to start with the blank board and iteratively apply the following rules until no moves are possible: Try all four edges; Swap (these are the only available options) and try again; Check if any of the subarrays are empty. If so, mark it and stop. Here's the problem. Find the minimum number of swaps needed to transform the board into an empty board. Preprocessing Each row and column is represented as a pair of integers (row, column), with -1 and 1, respectively, to mark the coordinates on the board that are occupied. There will be at least one row that is occupied (the first row), and at least one column that is occupied (the first column). Input Format Input is from a text file, with lines that begin with either a character in the range [,] or the special character "^". Each line contains an integer m (0 ≤ m ≤ 1000) and n (1 ≤ n ≤ 1000). The input is followed by m lines, each containing a pair of integers (row, column) where -1 ≤ row, column ≤ 1000. The first integer represents row (row = -1 means the first row, 0 means the second row, etc.), and the second integer represents column (column = -1 means the first column, 0 means the second column, etc.). The first line of input is the test line which will be followed by m lines of data. Each line of data begins with a single integer m followed by m pairs of integers (row, column). Output Format Output the smallest number of swaps that will transform the board into an empty board. If there are no valid moves, output "No valid moves". Test Sample Input: 4 3 -1 0 -1 -1 1 -1 1 1 -1 1 -1 0 Sample Output: No valid moves Explanation Here's an example: Input: 4 3 Output: No valid moves Given the 4/3 board, we first apply the four edge rules to get Output: Move -1 0 -1 Move -1 1 -1 Move -1 1 -1 Move -1 0 -

ee43de4aa9