Matrix Cell Value Placement
You are provided with an integer N
representing the size of an N
* N
matrix. Initially, each cell of the matrix is empty. You are also given a number K
, indicating the number of tasks. Each task involves specifying two integers, I
and J
, where I
represents the ith row and J
represents the jth column of the matrix.
Your goal is to perform every task sequentially. In each task, you place 0
in each cell of the ith row and jth column. After all tasks are completed, you need to return an array of size K
. The nth element of the array should indicate the number of empty cells in the matrix after executing the nth task.
Input:
The first line contains a single integer T, representing the number of test cases.
For each test case, the first line contains two integers N
and K
(N
is the dimension of the matrix and K
is the number of tasks).
Following this, each of the next K
lines contains two integers I
and J
.
Output:
For each test case, output an array indicating the number of empty cells in the matrix after each task, printed on a new line.
Example:
Example with N = 3, K = 2 tasks:
Initial Matrix:
[[ 'NULL', 'NULL', 'NULL']
['NULL', 'NULL', 'NULL']
['NULL', 'NULL', 'NULL'] ]
Task 1: (0, 0)
Matrix after task:
[[0, 0, 0]
[0, 'NULL', 'NULL']
[0, 'NULL', 'NULL'] ]
Empty cells: 4
Task 2: (1, 0)
Matrix after task:
[[0, 0, 0]
[0, 0, 0]
[0, 'NULL', 'NULL'] ]
Empty cells: 2
Return the array [4, 2]
Constraints:
- 1 <= T <= 5
- 1 <= N <= 105
- 0 <= K <= 105
- 0 <= I, J < N
Note:
Cells are considered empty if they do not contain any value. Indexing is 0-based.
Be the first one to answer
Add answer anonymously...
Top Deutsche Bank Technical Analyst-Intern interview questions & answers
Top HR questions asked in Deutsche Bank Technical Analyst-Intern
>
Deutsche Bank Technical Analyst-Intern Interview Questions
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