Find the Submatrix which holds the given co-ordinate
Last Updated : 19 Sep, 2022
Given a matrix mat of N*N (N is a perfect square|) and two points x and y, the task is to return all the elements of the submatrix in which the element A[x][y] lies.
Note: The matrix is divided into N equal submatrix each of size K*K (where K is the square root of N)
Approach: The problem can be solved based on the following observation:
An element at index (x, y) in a square matrix of perfect square length, lies in submatrix[n*(x/n), (n*(y/n)], where each value shows the positioning with respect to other submatrices. So the idea is to just print that submatrix.
Follow the steps mentioned below to implement the idea:
Find square root on N.
Store the submatrix where the coordinate (x, y) lies in a new matrix.
Return the new array.
Below is the implementation of the above approach.