Pop-It
InterviewTime limit1sMemory limit1024 MB
Given an h by w grid of 0s and 1s, find the fewest cells to flip so that every cell has the same value.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Pop-it, from the English phrase pop it, is a button toy that became popular among children and teenagers in spring 2021. It is made of rubber or silicone, and pressing a dome makes a clicking sound. The domes are called bumps, after the bubble wrap that makes a similar popping sound when pressed. (Wikipedia)
In this problem, a pop-it is a rectangle of height and width . Each unit cell holds one bump. Every bump is either pushed out or pushed in. We mark pushed out as 0 and pushed in as 1. Flipping a bump changes its state to the opposite.
Dasha wants to restore the pop-it to the way it was sold, where all bumps are in the same state. What is the minimum number of bumps Dasha must flip?
Input
The first line contains two integers and , the height and width of the pop-it (). Each of the next lines contains characters, each 0 or 1, with no spaces. These lines describe the state of the bumps.
Output
Print one integer, the minimum number of bumps that must be flipped so that all bumps are in the same state.