✅ EASY C++ SOLUTION ☑️
PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand
# **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/pratay_nandy/]()**\n\n# Approach\nThe provided C++ code is aiming to find the maximum product of two distinct elements in the given vector `nums`. It uses two variables, `num1` and `num2`, to keep track of the two largest elements encountered while iterating through the vector. The final result is the product of these two largest elements minus one.\n\nHere\'s a step-by-step explanation of the approach:\n\n1. Initialize two variables, `num1` and `num2`, to store the two largest elements. Initialize them with the minimum possible integer value (`INT_MIN`) to ensure that any element in the array will be greater.\n\n2. Iterate through each element `num` in the vector `nums`.\n\n3. Check if the current element `num` is greater than or equal to the current largest element `num1`. If true:\n   - Update `num2` with the value of `num1`.\n   - Update `num1` with the current element `num`.\n\n4. If the current element `num` is not greater than or equal to `num1` but is greater than `num2`, update `num2` with the value of the current element `num`.\n\n5. After the loop, `num1` and `num2` will contain the two largest elements in the vector.\n\n6. Return the product of the two largest elements minus one: `(num2 - 1) * (num1 - 1)`.\n\n\n# Complexity\n- Time complexity:**0(N)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:**0(1)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxProduct(vector<int>& nums) {\n        int n = nums.size();\n        int num1 = INT_MIN;\n        int num2 = INT_MIN;\n        for(int num : nums)\n        {\n            if(num >= num1){\n            num2 = num1;\n            num1 = num; \n            }\n            else if(num > num2)\n            {\n                num2 = num;\n            }\n        }\n        return (num2-1)*(num1-1);\n    }\n};\n```
['Array', 'C++']