[LeetCode]#1913. Maximum Product Difference Between Two Pairs

  • For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
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 for the second pair (2, 4).
The product difference is (6 * 7) - (2 * 4) = 34.
  1. sorted it as [2,4,5,6,7]
  2. return sorted location[-1]x[-2] -[0]x[1]
class Solution:
def maxProductDifference(self, nums):

return (sorted(nums)[-1]*sorted(nums)[-2])-(sorted(nums)[0]*sorted(nums)[1])




Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Beginner’s Basic SQL for Data Science using PostgreSQL

My deployed AI application on Ainize

How I discovered my passion for web design

Denial of Service(DoS) By Regex

Scrum is Devops’ Evil Twin!

How Optional Can Improve Your Productivity Writting Java

Kubernetes monitoring with Prometheus in 15 minutes

3 Things Counseling Can Teach Software Developers: Part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

Basic Data Structure and Algorithms in Python

LeetCode Patterns Adventure 13 — Remove Linked List Elements


Implementing Linked List Operations in Python