💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯
Intuition\n\n\nThese are the almost same questions which are similar to this one which are as follows :-\n\n---\nQ - 1460 --> https://leetcode.com/problems/make
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/08a317f7-788c-4cd4-803f-3da9cc07cfa1_1722001592.2612438.jpeg)\n![Screenshot 2024-07-26 190450.png](https://assets.leetcode.com/users/images/0c0d54fc-6dcb-468d-a701-8f6369ce935c_1722001601.8011763.png)\nThese are the almost same questions which are similar to this one which are as follows :-\n\n---\n***Q - 1460 -->*** https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/solutions/5538697/easiestfaster-lesser-cpython3javacpythoncexplained-beats\n\n***Q - 1534 -->*** https://leetcode.com/problems/count-good-triplets/solutions/5538845/easiestfaster-lesser-cpython3javacpythoncexplained-beats\n\n***Q - 2475-->*** https://leetcode.com/problems/number-of-unequal-triplets-in-array/solutions/5538953/easiestfaster-lesser-cpython3javacpythoncexplained-beats\n\n***Q - 2367 -->*** https://leetcode.com/problems/number-of-arithmetic-triplets/solutions/5539085/easiestfaster-lesser-cpython3javacpythoncexplained-beats\n\n---\n\n\n```C++ []\n// Start Of Anuj Bhati aka Edwards310\'s Template...\n#pragma GCC optimize("O2")\n#include <bits/stdc++.h>\n\nusing namespace std;\n#define INF 1000000005\n#define FOR(a, b, c) for (int a = b; a < c; a++)\n#define FOR1(a, b, c) for (int a = b; a <= c; ++a)\n#define Rep(i, n) FOR(i, 0, n)\n\n// end of Anuj Bhati\'s aka Edwards310\'s Template\nclass Solution {\npublic:\n    int minimumSum(vector<int>& nums) {\n        int n = nums.size();\n        int ans = INF;\n        Rep(i, n - 2){\n            FOR(j, i + 1, n - 1){\n                if(nums[i] < nums[j]){\n                    FOR(k, j + 1, n){\n                        if(nums[k] < nums[j])\n                            ans = fmin(ans, (nums[i] + nums[j] + nums[k]));\n                    }\n                }\n            }\n        }\n        return ans == INF ? - 1 : ans;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def minimumSum(self, nums: List[int]) -> int:\n        n = len(nums)\n        ans = float(\'inf\')\n        for i in range(n - 2):\n            for j in range(i + 1, n - 1):\n                if nums[i] < nums[j]:\n                    for k in range(j + 1, n):\n                        if nums[k] < nums[j]:\n                            ans = min(ans, nums[i] + nums[j] + nums[k])\n\n\n        return -1 if ans == float(\'inf\') else ans\n```\n```C# []\npublic class Solution {\n    public int MinimumSum(int[] nums) {\n        int n = nums.Length;\n        int ans = 1000000005;\n        for(int i = 0; i < n - 2; i++)\n            for(int j = i + 1; j < n - 1; ++j)\n                if(nums[i] < nums[j])\n                    for(int k = j + 1; k < n; ++k)\n                        if(nums[k] < nums[j])\n                            ans = Math.Min(ans, (nums[i] + nums[j] + nums[k]));\n\n        return ans == 1000000005  ? -1 : ans;\n    }\n}\n```\n```Java []\nclass Solution {\n    public int minimumSum(int[] nums) {\n        int n = nums.length;\n        int ans = 1000000005;\n        for(int i = 0; i < n - 2; i++)\n            for(int j = i + 1; j < n - 1; ++j)\n                if(nums[i] < nums[j])\n                    for(int k = j + 1; k < n; ++k)\n                        if(nums[k] < nums[j])\n                            ans = Math.min(ans, (nums[i] + nums[j] + nums[k]));\n\n        return ans == 1000000005  ? -1 : ans;\n    }\n}\n```\n```python []\nclass Solution(object):\n    def minimumSum(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        n = len(nums)\n        ans = float(\'inf\')\n        for i in range(n - 2):\n            for j in range(i + 1, n - 1):\n                if nums[i] < nums[j]:\n                    for k in range(j + 1, n):\n                        if nums[k] < nums[j]:\n                            ans = min(ans, nums[i] + nums[j] + nums[k])\n\n\n        return -1 if ans == float(\'inf\') else ans\n```\n```C []\nint minimumSum(int* nums, int numsSize) {\n    int n = numsSize;\n        int ans = 1000000005;\n        for(int i = 0; i < n - 2; i++)\n            for(int j = i + 1; j < n - 1; ++j)\n                if(nums[i] < nums[j])\n                    for(int k = j + 1; k < n; ++k)\n                        if(nums[k] < nums[j])\n                            ans = fmin(ans, (nums[i] + nums[j] + nums[k]));\n\n        return ans == 1000000005  ? -1 : ans;\n}\n```\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n      O(n^3)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n      O(1)\n# Code\n```\nclass Solution {\n    public int minimumSum(int[] nums) {\n        int n = nums.length;\n        int ans = 1000000005;\n        for(int i = 0; i < n - 2; i++)\n            for(int j = i + 1; j < n - 1; ++j)\n                if(nums[i] < nums[j])\n                    for(int k = j + 1; k < n; ++k)\n                        if(nums[k] < nums[j])\n                            ans = Math.min(ans, (nums[i] + nums[j] + nums[k]));\n\n        return ans == 1000000005  ? -1 : ans;\n    }\n}\n```\n![th.jpeg](https://assets.leetcode.com/users/images/1b987775-08b2-45d1-86b3-bca573d70ebd_1722001858.481272.jpeg)\n
['Array', 'C', 'Python', 'C++', 'Java', 'Python3', 'C#']