Algorithm · Walmart Labs · Easy
Requirements Inputs are A: int[] and B: int[], and both arrays have identical length n. Rearrange B however you like. For a resulting arrangement, let s equal Σ_{i: B[i] > A[i]} B[i]. Your task is to return the largest possible value of s across every permutation of B. The stated bounds are moderate: n is large enough that an O(n²) approach is not acceptable, so target O(n log n). Examples Worked example: A = [3, 6, 4], B = [5, 8, 2]. Sort both arrays in increasing order,…
Checking your access…