FastPrepMin Flips to Make Grid Palindrome
Problems/Min Flips to Make Grid Palindrome

Min Flips to Make Grid Palindrome

Google logoGoogle● HardPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source says a flip changes 0 to 1, but under that rule the example has no solution. This version allows a bit to be flipped in either direction, making the corrected answer 2. The source does not include input limits. The judged core task matches the visible source at about 95%.

You're working on a data storage system that represents information in a binary grid. For error correction and symmetry, every row and column must be a palindrome.

Additionally, due to hardware constraints, the total number of 1s must be divisible by 4.

You may flip any bit, changing 0 to 1 or 1 to 0. Return the minimum number of flips needed to make the grid valid.

Function

minFlips(grid: int[][]) → int

Examples

Example 1

grid = [[1, 0, 1], [0, 1, 0], [1, 0, 0]]return = 2
grid
012010110102100

Flip the bottom-right 0 to 1 and the center 1 to 0. The resulting grid is [[1, 0, 1], [0, 0, 0], [1, 0, 1]], whose rows and columns are palindromes and whose four 1s are divisible by 4. One flip cannot satisfy both requirements, so the minimum is 2.

Constraints

  • grid is a non-empty rectangular matrix.
  • Every value in grid is either 0 or 1.

More Google Phone Screen questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Town Temperature Regression AnalysisCitadel · PHONE SCREENCitadel interview questions
  • Balanced Human, Model and Task AssignmentOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Best Starting Cell for Restaurant DistanceDoorDash · PHONE SCREENDoorDash interview questions
  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • Daily Temperature By TownTwo Sigma · OATwo Sigma interview questions
  • Minimum Replacements Required to Make a Matrix BalancedMicrosoft · OAMicrosoft interview questions
  • Minimum Row Deletions to Prevent a Target ORInMobi · ONSITE INTERVIEWInMobi interview questions
  • Flipping MatrixZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
  • Calculate the Max ValueAmazon · OA
  • Server SelectionAirbnb · OAAirbnb interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minFlips(int[][] grid) {
      // write your code here
    }

}
Checking account…