
Asked in Hike
Maximum Difference in Matrix
Given an n x n
matrix mat[n][n]
of integers, find the maximum value of mat[c][d] - mat[a][b]
for all possible indices where c > a
and d > b
.
Input:
The first line contains a single integer T representing the number of test cases. For each test case:
The first line contains a single integer N denoting the size of the matrix.
The next N lines contain 'N' integers each, where each line represents a row of the matrix.
Output:
For each test case, output a single integer indicating the maximum difference calculated for that test case.
Each result should be printed on a new line.
Example:
Input:
1
3
1 2 3
4 5 6
7 8 9
Output:
8
Explanation:
In this matrix, the maximum difference is 8
(from mat[2][2] - mat[0][0]
).
Constraints:
1 ≤ N ≤ 100
1 ≤ mat[i][j] ≤ 108
Note:
No need to print in your solution, just implement the function.

AnswerBot
4mo
Find the maximum difference between elements in a matrix with specific conditions.
Iterate through all possible pairs of indices (a, b) and (c, d) where c > a and d > b.
Calculate the difference between...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Hike
Q. Infix to Postfix Conversion Convert a given infix expression, represented as a s...read more
Q. Maximum Size Rectangle Sub-matrix with All 1's Problem Statement You are provide...read more
Q. Binary Tree Maximum Path Sum Problem Statement Determine the maximum path sum fo...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Hike Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

