Query and Matrix Problem Statement
You are given a binary matrix with 'M' rows and 'N' columns, initially consisting of all 0s. You will receive 'Q' queries, which can be of four types:
Query 1: 1 R index
Query 2: 1 C index
Query 3: 2 R index
Query 4: 2 C index
In each query, the first input is the type of the query, the second input indicates whether to consider the row ('R') or the column ('C'), and the third input is the index of the row/column.
For each type 1 query, flip the elements of the row/column at the given index. For each type 2 query, output the number of zeros present in the row/column at the given index.
Example:
Input:
M = 3, N = 3
Queries: 1R1, 1R2, 2C1
Output:
1
Explanation:
The matrix changes as per the queries, and the final query 2C1 returns the count of zeros in the 1st column, which is 1.
Constraints:
- 1 <= T <= 10
- 1 <= M, N <= 100
- 1 <= Q <= 1000
- 1 <= R <= M
- 1 <= C <= N
- type = 1, 2
- Time limit: 1 sec
Note:
Note that the matrix is a binary matrix, meaning it only contains either 0 or 1. You don’t need to print anything; it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Popular interview questions of Full Stack Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app