1913 - return  ( largest * second largest ) - ( smallest * second smallest )
---\n\nAlgo\n- Sort the numbers in ascending order\n  - First two are the1st and 2nd smallest,  say s1, s2,  these are [0] and [1] elements in array\n  - Last t
---\n\n**Algo**\n- Sort the numbers in ascending order\n  - First two are the1st and 2nd smallest,  say `s1`, `s2`,  these are `[0]` and `[1]` elements in array\n  - Last two are the 1st and 2nd largest, say `L1`, `L2`,  these are `[n-1]` and `[n-2]` elements in array\n- Multiply largest ones  `L1 * L2`\n- Multiply smallest ones `s1 * s2`\n- Return their substraction result:   `L1 * L2  -  s1 * s2`\n  - This produces the `maximum` of `product difference`\n\nHope it is simple to understand.\n\n---\n\n```\nvar maxProductDifference = function(A) {\n    let n = A.length;\n\n    A.sort((a, b) => a - b);\n    return (A[n - 1] * A[n - 2]) - (A[0] * A[1])\n};\n```\n\n**100ms**\n\n![image](https://assets.leetcode.com/users/images/cf3af89b-04a6-480a-870d-66608e4fa409_1624770274.3186524.png)\n\n---\n\n\n```\nvar maxProductDifference = function (a) {\n  const n = a.length\n\n  a.sort((a, b) => a - b)\n\n  const first = a[0]\n  const second = a[1]\n\n  const last = a[n - 1]\n  const secondLast = a[n - 2]\n\n  return last * secondLast - first * second\n}\n```\n\n---\n
['JavaScript']