[C++] Greedy
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\n- Find the biggest 2 elements and the smallest 2 elements in the array\r\n\r\n# App
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n- Find the biggest 2 elements and the smallest 2 elements in the array\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n- Iterate on the array\r\n  - Track the top 2 maximum values\r\n  - Track the top 2 minimum values\r\n\r\n# Complexity\r\n- Time complexity: $$O(n)$$\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity: $$O(1)$$\r\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\r\n\r\n# Code\r\n```\r\nclass Solution {\r\npublic:\r\n    // time/space: O(n)/O(1)\r\n    int maxProductDifference(vector<int>& nums) {\r\n        long long max1 = INT_MIN, max2 = INT_MIN;\r\n        long long min1 = INT_MAX, min2 = INT_MAX;\r\n        for (auto& num : nums) {\r\n            // track the top 2 maximum values\r\n            if (num > max1) {\r\n                max2 = max1;\r\n                max1 = num;\r\n            }\r\n            else if (num > max2) {\r\n                max2 = num;\r\n            }\r\n            // track the top 2 minimum values\r\n            if (num < min1) {\r\n                min2 = min1;\r\n                min1 = num;\r\n            }\r\n            else if (num < min2) {\r\n                min2 = num;\r\n            }\r\n        }\r\n        return (max1 * max2) - (min1 * min2);\r\n    }\r\n};\r\n```
['Iterator', 'C++']