Minimum Changes to Draw a Y
Updated
Problem statement
grid is an odd n by n matrix containing only 0, 1, and 2. The Y consists of both upper diagonals through the center and the vertical cells below the center.
Change the fewest cells so all Y cells share one value and all non-Y cells share a different value. Return the minimum changes.
Function
minimumYChanges(grid: int[][]) → intExamples
Example 1
grid = [[1,2,2],[1,1,0],[0,1,0]]return = 3Trying all distinct Y and background values yields a minimum of three changes.
Example 2
grid = [[0,0,0],[0,0,0],[0,0,0]]return = 4Use 0 for the five Y cells and recolor the four non-Y cells.
Constraints
3 <= n <= 501- n is odd.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
- Count Case-Insensitive Key ChangesOA · Seen Sep 2024
Similar questions at other companies
- Count 2x2 Submatrices by Black CellsTikTok · OATikTok interview questions
- Count L-Shaped PlotsUber · OAUber interview questions
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Optimal Office PlacementRoblox · OARoblox interview questions
- Unique Grid PathsMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
- Count Paths from the Top Left to the Bottom RightAmazon · ONSITE INTERVIEW
- Count Communicating ServersFox Corporation · PHONE SCREEN
- Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
- DSA Round: Maximum Score Grid PathOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Distinct Values on Maximum-Sum FramesCapital One · OACapital One interview questions