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.
AnswerBot
4mo

Find the maximum value of a given expression involving two arrays.

  • Iterate through all possible pairs of indices i and j to calculate the expression value

  • Use absolute difference to handle negative valu...read more

Help your peers!
Select
Add answer anonymously...

Delhivery Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Trapping Rain Water Problem Statement You are given a long type array/list ARR o...read more
A Software Developer Intern was asked Q. Maximum Value of Modulus Expression Problem You are provided with two arrays ARR...read more
A Software Developer Intern was asked Q. Reverse Linked List Problem Statement Given a Singly Linked List of integers, yo...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Trapping Rain Water Problem Statement You are given a long type array/list ARR o...read more
A Software Developer Intern was asked Q2. Maximum Value of Modulus Expression Problem You are provided with two arrays ARR...read more
A Software Developer Intern was asked Q3. Reverse Linked List Problem Statement Given a Singly Linked List of integers, yo...read more
Delhivery Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits