Maximum Value of Modulus Expression Problem
You are provided with two arrays ARR1
and ARR2
both having an equal length N
. Your objective is to compute the maximum value of the expression:
|ARR1[ i ] - ARR1[ j ]| + |ARR2[ i ] - ARR2[ j ]| + |i - j|, where 0 <= i, j < n
and |A|
denotes the absolute (non-negative) value of A
.
Input:
The first line provides an integer T
representing the number of test cases.
Each test case contains:
- A single integer N
, denoting the length of arrays ARR1
and ARR2
.
- A line of N
space-separated integers describing the elements of array ARR1
.
- A line of N
space-separated integers describing the elements of array ARR2
.
Output:
For each test case, output a single integer indicating the maximum value of the expression. Each test case output should be printed on a separate line.
Example:
Input:
n = 4, ARR1 = [1, 2, 3, 4], ARR2 = [-1, 3, 4, 2]
Output:
9
Explanation: The maximum value of the expression is found from indices i = 0
and j = 3
. Computing the expression: |ARR1[0] - ARR2[3]| + |ARR2[0] - ARR2[3]| + |0 - 3| = |1 - 4| + |-1 - 2| + |-3| = 3 + 3 + 3 = 9
So the result is 9
.
Constraints:
1 <= T <= 100
1 <= N <= 1000
-10^6 <= ARR1[i], ARR2[i] <= 10^6
Note:
No need to handle input/output operations. Focus on implementing the function to compute the maximum value.
Be the first one to answer
Add answer anonymously...
Top Delhivery Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
Delhivery Software Developer Intern 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