Flip Grid
Practice
3.2 (4 votes)
Implementation
Graphs
Algorithms
Brute force
Breadth First search
Problem
73% Success 383 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Alice was given two \(4\) x \(4\) binary grids, \(A\) and \(B\). She wants to convert grid \(A\) to \(B\). She can perform any of the following operations any number of times on grid \(A\) (she can't modify \(B\)): 

  1. Rotate grid \(A\) clockwise by \(90\) degrees. 
  2. Flip a row in grid \(A\) i.e. change all 0's in the chosen row to 1's, and 1's to 0's. 
  3. Flip a column in grid \(A\) i.e. change all 0's in the chosen column to 1's, and 1's to 0's. 

Output the minimum number of moves that Alice needs to convert \(A\) to \(B\), or \(-1\) if it is impossible to make both grids equal. 

 

INPUT FORMAT

The first \(4\) lines of the input each contain a string of length \(4\) - denoting the rows in grid \(A\), each character in the string is either \(0\) or \(1\)

The next line is an empty line. 

The remaining \(4\) lines of the input each contain a string of length \(4\) - denoting the rows in grid \(B\), each character in the string is either \(0\) or \(1\).

 

OUTPUT FORMAT 

The first and only line of the output should contain the minimum number of operations Alice needs to convert grid \(A\) to \(B\), or \(-1\) if it's impossible to do so, using the operations in the statement. 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
32 votes
Tags:
AlgorithmsApprovedBreadth First SearchGraphsMediumOpen
Points:30
16 votes
Tags:
AlgorithmsBreadth First SearchGraphsMedium
Points:30
90 votes
Tags:
AlgorithmsApprovedBreadth First SearchDepth First SearchGraphsMediumReady