FastPrepFlip Rows and Columns, Count Zeros
Problems/Flip Rows and Columns, Count Zeros

Flip Rows and Columns, Count Zeros

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2021 report from a virtual off-campus Nutanix hiring loop for an MTS intern role lists this as the first of two questions in the coding round. A matrix of 0s and 1s starts as all 0s. Each query names a type, R or C, and a row or column index. Type 1 flips that whole row or column. Type 2 asks how many 0s it holds. The report puts the number of rows and the number of queries at up to 10^5.

The report does not say how rows and columns are numbered, how many columns there can be, or how the answers come back. Here each query is one string with single spaces and an index without leading zeros, such as "1 R 3". Rows and columns are numbered from 1, and both go up to 10^5. You return the type 2 answers in order, or an empty array when there are none. This version allows at most 2 * 10^4 queries instead of 10^5, so every test stays small enough to run.

Our version is about 90% the same as the reported question.

You have a binary matrix with n rows and m columns. Rows are numbered from 1 to n and columns from 1 to m. At the start, every cell is 0.

Each entry of queries is a string "t X i". Here t is the query type, X is R for a row or C for a column, and i is the row or column number.

  • Type 1 ("1 R i" or "1 C i"): flip every cell in row i or column i. A 0 becomes 1 and a 1 becomes 0.
  • Type 2 ("2 R i" or "2 C i"): count the cells in row i or column i that are 0 right now.

Process the queries in order. Return the answers to the type 2 queries in the order they were asked. If there is no type 2 query, return an empty array.

Function

processMatrixQueries(n: int, m: int, queries: String[]) → int[]

Examples

Example 1

n = 3m = 4queries = ["1 R 2","1 C 3","2 R 2","2 C 3","2 R 1","1 R 2","2 C 3"]return = [1,1,3,0]

Row 2 is flipped, so it becomes 1 1 1 1. Then column 3 is flipped, which turns the matrix into rows 0 0 1 0, 1 1 0 1 and 0 0 1 0.

  • "2 R 2": row 2 is 1 1 0 1, with one 0.
  • "2 C 3": column 3 holds 1, 0, 1, with one 0.
  • "2 R 1": row 1 is 0 0 1 0, with three 0s.

Row 2 is flipped again and becomes 0 0 1 0. Now column 3 holds 1, 1, 1, so the last query gives 0. The answer is [1, 1, 3, 0].

Example 2

n = 1m = 5queries = ["1 C 1","1 C 5","1 C 1","1 R 1","2 R 1"]return = [1]

Column 1 is flipped twice, so it ends where it started. Column 5 is flipped once, so the row is 0 0 0 0 1. Flipping row 1 gives 1 1 1 1 0, which has one 0. The answer is [1].

Example 3

n = 2m = 2queries = ["1 R 1","1 C 2"]return = []

Both queries are flips and nothing is asked, so the answer is an empty array.

Constraints

  • 1 <= n, m <= 10^5
  • 1 <= queries.length <= 2 * 10^4
  • Each queries[j] has the form "t X i" with single spaces, where t is 1 or 2 and X is R or C.
  • i is written without leading zeros. For R queries, 1 <= i <= n. For C queries, 1 <= i <= m.

More Nutanix Online Assessment questions

  • Good SubsequencesOA · Seen Jul 2026
  • Min Cost to Connect All PointsOA · Seen Jun 2026
  • Digit Changes for a Multiple of 9OA · Seen Aug 2025
  • Gas Station Loop StartOA · Seen Aug 2025
  • Number of Players (for MTS2)OA · Seen Oct 2024
  • Work Schedules (for MTS2)OA · Seen Oct 2024
  • Minimum Operations to Convert ArrayOA · Seen Apr 2024
  • No Adjacent CharactersOA · Seen Apr 2024
  • Build a BST From a ListOA · Seen Nov 2022
  • Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022

Similar questions at other companies

  • Repair One Movement InstructionOpenAI · OAOpenAI interview questions
  • Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
  • Scaled Dot-Product AttentionMeshy · OA
  • Count Straight-Line Word Occurrences in a GridVisa · OAVisa interview questions
  • Find Last CharacterGoogle · OAGoogle interview questions
  • Count Prioritized Binary-Run OperationsZipRecruiter · OAZipRecruiter interview questions
  • Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
  • Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
  • Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions
  • Collect Letters Along a Unique Grid PathApple · OAApple interview questions

Interview reports that mention this question

  • Nutanix Intern Debugging Round and Interviews: 25 Experiences

Nutanix interview experiences

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public int[] processMatrixQueries(int n, int m, String[] queries) {
        // Write your code here.
    }
}
Checking account…