Leaderboard
Showing:
Queries on a Matrix
Hard Accuracy: 0.0% Submissions: 0 Points: 8

You are given a matrix of dimension n*n. All the cells are initially, zero. You are given Q queries, which contains 4 integers a b c d where (a,b) is the TOP LEFT cell and (c,d) is the Bottom Right cell of a submatrix. Now, all the cells of This submatrix has to be incremented by one. After all the Q queries have been performed. Your task is to find the final resulting Matrix.
Note : Zero-Based Indexing is used for cells of the matrix. 

 

Example 1:

Input: n = 6, q = 6,
Queries = {{4,0,5,3},{0,0,3,4},{1,2,1,2}
,{1,1,2,3},{0,0,3,1},{1,0,2,4}}.
Output: {{2,1,1,1,0},{3,4,4,3,2,0},{3,4,4,3,2,0}
,{2,2,1,1,1,0},{1,1,1,1,0},{1,1,1,1,0}}

 

Your Task:
You don't need to read or print anything. Your task is to complete the function solveQueries() which takes n and Queries and input parameter and returns a matrix after performing all the queries.

 

Expected Time Complexity: O(n2)
Expected Space Complexity: O(n2)

 

Constraints:
1 <= n <= 100
0 <= a <= c <= 99
0 <= b <= d <= 99
1 <= No. of Queries <= 1000

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Queries on a Matrix

Output Window