Maximum Combined Distance Across Five Arrays
Updated
Problem statement
You are given five integer arrays a, b, c, d and e, all of the same length n.
For two indices i and j (each from 0 to n - 1), define
f(i, j) = |a[i] - a[j]| + |b[i] - b[j]| + |c[i] - c[j]| + |d[i] - d[j]| + |e[i] - e[j]| + |i - j|
Return the largest value of f(i, j) over all pairs of indices. The two indices may be the same, in which case f(i, i) = 0.
Function
maxCombinedDistance(a: int[], b: int[], c: int[], d: int[], e: int[]) → intExamples
Example 1
a = [1,3]b = [2,0]c = [0,0]d = [5,4]e = [-1,1]return = 8With i = 0 and j = 1 the six terms are |1 - 3| = 2, |2 - 0| = 2, |0 - 0| = 0, |5 - 4| = 1, |-1 - 1| = 2 and |0 - 1| = 1. They add up to 8.
Choosing the same index twice gives 0, so the answer is 8.
Example 2
a = [0,4,1]b = [2,2,-3]c = [1,0,1]d = [0,0,0]e = [3,-1,2]return = 13- Indices 0 and 1:
4 + 0 + 1 + 0 + 4 + 1 = 10. - Indices 0 and 2:
1 + 5 + 0 + 0 + 1 + 2 = 9. - Indices 1 and 2:
3 + 5 + 1 + 0 + 3 + 1 = 13.
The best pair is indices 1 and 2, even though indices 0 and 2 are farther apart. The answer is 13.
Example 3
a = [7]b = [-2]c = [0]d = [9]e = [4]return = 0There is only one index, so i = j = 0 and every term is 0. The answer is 0.
Constraints
a.length == b.length == c.length == d.length == e.length == n1 <= n <= 5 * 10^4-10^6 <= a[i], b[i], c[i], d[i], e[i] <= 10^6
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA