FastPrepMinimum Changes to Draw a Y
Problems/Minimum Changes to Draw a Y

Minimum Changes to Draw a Y

ZipRecruiter logoZipRecruiter● MediumFULLTIMENEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two ZipRecruiter OA reports preserve ternary cells and minimum Y/non-Y recoloring; the stronger direct source fixes odd size, exact Y geometry, and all six foreground/background choices. One source lacks an employment label, so this record retains both NEW GRAD and FULLTIME evidence.

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[][]) → int

Examples

Example 1

grid = [[1,2,2],[1,1,0],[0,1,0]]return = 3
grid
012012211102010

Trying 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 = 4
grid
012000010002000

Use 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int minimumYChanges(int[][] grid) {
        // Write your code here.
    }

}
Checking account…