Welcome to the daily solving of our PROBLEM OF THE DAY with Ayush Tripathi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Matrix but also build up problem-solving skills.
A matrix is constructed of size n*n and given an integer ‘q’. The value at every cell of the matrix is given as, M(i,j) = i+j, where ‘M(i,j)' is the value of a cell, ‘i’ is the row number, and ‘j’ is the column number. Return the number of cells having value ‘q’.
Note: Assume, the array is in 1-based indexing.
Examples:
Input: n = 4, q = 7
Output: 2
Explanation: Matrix becomes
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
The count of 7 is 2.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/summed-matrix5834/1