Maximum Product Difference: NLogN
Problem can be solved in NLogN with 2 lines: sort and take the extremes. That's it. Problem and code are below, cheers, ACC. Maximum Product Difference Between Two Pairs - LeetCode 1913. Maximum Product Difference Between Two Pairs Easy 33 1 Add to List Share The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d) . For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16 . Given an integer array nums , choose four distinct indices w , x , y , and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized . Return the maximum such product difference . Example 1: Input: nums = [5,6,2,7,4] Output: 34 Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 ...