Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 1818. Minimum Absolute Sum Difference
Given two equal-length arrays, you may replace at most one element in nums1 with any other element from nums1 to minimize the sum of |nums1[i]-nums2[i]|; the challenge is to pick the single best replacement (index and value) that yields the largest reduction in total absolute difference. With n up to 1e5 and values up to 1e5, the typical approach is to pre-sort nums1 and for each index find the closest candidate to nums2[i] (e.g., via binary search) to compute the maximal possible decrease and apply it.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.