Min Flips to Make Grid Palindrome
Updated
Problem statement
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[][]) → intExamples
Example 1
grid = [[1, 0, 1], [0, 1, 0], [1, 0, 0]]return = 2Flip 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
gridis a non-empty rectangular matrix.- Every value in
gridis either0or1.
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