Matrix Rank Calculation
Given a matrix ARR
of dimensions N * M
, your task is to determine the rank of the matrix ARR
.
Explanation:
The rank of a matrix is defined as:
(a) The maximum number of linearly independent column vectors in the matrix, or
(b) The maximum number of linearly independent row vectors in the matrix.
Both definitions are equivalent.
Linear independence is defined as follows:
In vector space theory, a set of vectors is considered linearly dependent if there is a nontrivial linear combination of the vectors that equates to the zero vector. If no such linear combination exists, then the vectors are linearly independent.
Input:
The first line contains a single integer ‘T’ denoting the number of test cases.
Each test case consists of:
- The first line contains two space-separated integers, ‘N’ and ‘M’, representing the number of rows and the number of columns respectively.
- The next ‘N’ lines each contain ‘M’ integers that represent the matrix elements.
Output:
For each test case, return the rank of the matrix.
Example:
Input:
2
3 3
1 2 3
4 5 6
7 8 9
2 2
1 2
3 4
Output:
2
2
Constraints:
1 <= T <= 10
1 <= N, M <= 500
-10^4 <= ARR[i][j] <= 10^4
Where ARR[i][j]
denotes the matrix element at the jth column in the ith row of ARR
.
Time Limit: 1 sec
Note:
You are not required to print anything; it has already been taken care of. Just implement the given function and return the answer.
Be the first one to answer
Add answer anonymously...
Top Microsoft Corporation Full Stack Developer interview questions & answers
Popular interview questions of Full Stack Developer
Top HR questions asked in Microsoft Corporation Full Stack Developer
>
Microsoft Corporation Full Stack Developer 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