Simple Java || C++ Code ☠️
java []\nclass Solution {\n    public double minimumAverage(int[] nums) {\n        int n = nums.length;\n        ArrayList<Integer> ind = new ArrayList<Integer>
```java []\nclass Solution {\n    public double minimumAverage(int[] nums) {\n        int n = nums.length;\n        ArrayList<Integer> ind = new ArrayList<Integer>();\n        double res;\n        double min = 51;\n        for(int i=0;i<n/2;i++){\n            res=help(nums,ind);\n            if(min>res){\n                min=res;\n            }\n        }\n        return min;\n    }\n    public double help(int[] nums,ArrayList<Integer> ind){\n        double min=51,max=0;\n        int mini=0,maxi=0;\n        for(int i=0;i<nums.length;i++){\n            if(ind.contains(i)){\n                continue;\n            }\n            if(min>nums[i]){\n                min=(double) nums[i];\n                mini=i;\n            }\n            if(max<nums[i]){\n                max=(double) nums[i];\n                maxi=i;\n            }\n        }\n        ind.add(mini);\n        ind.add(maxi);\n        double avg = (min+max)/2.0;\n        return avg;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    double minimumAverage(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> ind;\n        double res;\n        double min = 51;\n        for(int i=0;i<n/2;i++){\n            res=help(nums,ind);\n            if(min>res){\n                min=res;\n            }\n        }\n        return min;\n    }\n    double help(vector<int>& nums,vector<int>& ind){\n        double min=51,max=0;\n        int mini=0,maxi=0;\n        for(int i=0;i<nums.size();i++){\n            int count = std::count(ind.begin(), ind.end(), i);\n            if(count > 0){\n                continue;\n            }\n            if(min>nums[i]){\n                min=(double) nums[i];\n                mini=i;\n            }\n            if(max<nums[i]){\n                max=(double) nums[i];\n                maxi=i;\n            }\n        }\n        ind.push_back(mini);\n        ind.push_back(maxi);\n        double avg = (min+max)/2.0;\n        return avg;\n    }\n};\n```\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n1. **Tracking Indices**:\n   - By using `ind`, you attempt to avoid re-evaluating the same elements across multiple iterations. This can help in exploring different pairs of minimum and maximum values.\n\n2. **Multiple Iterations**:\n   - Running the main loop `n/2` times is an attempt to ensure different subsets of elements are considered, potentially leading to a more optimal minimum average.\n\n3. **Finding Min and Max**:\n   - In each call to `help`, the code identifies the smallest and largest elements not yet considered (`ind`), calculates their average, and marks these indices as processed.\n\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n1. **Initialization**:\n   - The method `minimumAverage` initializes an `ArrayList` called `ind` to keep track of indices of elements that have already been considered.\n   - It sets a variable `min` to `51`, assuming the range of elements in the array is between `0` and `50`.\n\n2. **Main Loop (`minimumAverage` method)**:\n   - The loop `for (int i = 0; i < n / 2; i++)` runs `n/2` times (where `n` is the length of the array). This is a heuristic choice, probably to ensure that multiple different pairs of minimum and maximum values are considered.\n   - In each iteration, the `help` method is called with the array and the `ind` list.\n   - The result of the `help` method (`res`) is compared to `min`, and if `res` is smaller, `min` is updated to `res`.\n\n3. **Finding Minimum and Maximum (`help` method)**:\n   - The method initializes `min` to `51` and `max` to `0` to ensure any element in `nums` will update these values.\n   - It iterates over each element in the array. If the index of the current element is in `ind`, it skips that element.\n   - If the element is smaller than the current `min`, `min` is updated to this element, and its index is stored in `mini`.\n   - If the element is larger than the current `max`, `max` is updated to this element, and its index is stored in `maxi`.\n   - After identifying the minimum and maximum values, their indices (`mini` and `maxi`) are added to `ind`.\n   - The average of `min` and `max` is calculated and returned.\n\n### Detailed Steps\n\n1. **First Iteration**:\n   - `ind` is empty, so the `help` method searches for the minimum and maximum values in the entire array.\n   - The indices of these values are added to `ind`.\n   - The average of these values is computed and compared to the current `min` average.\n\n2. **Subsequent Iterations**:\n   - `ind` now contains some indices, so the `help` method skips these indices in subsequent searches.\n   - The method continues to search for new minimum and maximum values among the remaining elements.\n   - The indices of these new values are added to `ind`, preventing them from being reconsidered.\n   - This process continues for `n/2` iterations, each time potentially finding new pairs of minimum and maximum values and computing their averages.\n\n\n**Example Array**: `[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]`\n\n### Initial Setup\n- Initialize `ind` to an empty list.\n- Set `min` (the variable for tracking the minimum average) to `51`.\n\n### First Iteration\n\n1. Call `help` with the full array `[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]` and empty `ind`.\n\n   **Inside `help`**:\n   - Initialize `min` to `51` and `max` to `0`.\n   - Iterate through the array:\n     - Element `3`: Update `min` to `3`, `mini` to `0`.\n     - Element `1`: Update `min` to `1`, `mini` to `1`.\n     - Element `4`: Update `max` to `4`, `maxi` to `2`.\n     - Elements `1, 5, 9, 2, 6, 5, 3, 5`: Update `max` to `9`, `maxi` to `5`.\n   - Add indices `1` and `5` to `ind`.\n   - Calculate average: `(1 + 9) / 2.0 = 5.0`.\n   - Return `5.0` to `minimumAverage`.\n\n2. Compare returned value `5.0` with `min` (`51`), update `min` to `5.0`.\n\n### Second Iteration\n\n1. Call `help` with the array and `ind` containing `[1, 5]`.\n\n   **Inside `help`**:\n   - Initialize `min` to `51` and `max` to `0`.\n   - Iterate through the array, skipping indices `1` and `5`:\n     - Element `3`: Update `min` to `3`, `mini` to `0`.\n     - Element `4`: Update `max` to `4`, `maxi` to `2`.\n     - Elements `1, 5, 9, 2, 6, 5, 3, 5`: Update `max` to `6`, `maxi` to `7`.\n   - Add indices `0` and `7` to `ind`.\n   - Calculate average: `(3 + 6) / 2.0 = 4.5`.\n   - Return `4.5` to `minimumAverage`.\n\n2. Compare returned value `4.5` with `min` (`5.0`), update `min` to `4.5`.\n\n### Third Iteration\n\n1. Call `help` with the array and `ind` containing `[1, 5, 0, 7]`.\n\n   **Inside `help`**:\n   - Initialize `min` to `51` and `max` to `0`.\n   - Iterate through the array, skipping indices `1, 5, 0, 7`:\n     - Element `4`: Update `min` to `4`, `mini` to `2`.\n     - Element `2`: Update `min` to `2`, `mini` to `6`.\n     - Elements `5, 3, 5`: Update `max` to `5`, `maxi` to `4`.\n   - Add indices `6` and `4` to `ind`.\n   - Calculate average: `(2 + 5) / 2.0 = 3.5`.\n   - Return `3.5` to `minimumAverage`.\n\n2. Compare returned value `3.5` with `min` (`4.5`), update `min` to `3.5`.\n\n### Fourth Iteration\n\n1. Call `help` with the array and `ind` containing `[1, 5, 0, 7, 6, 4]`.\n\n   **Inside `help`**:\n   - Initialize `min` to `51` and `max` to `0`.\n   - Iterate through the array, skipping indices `1, 5, 0, 7, 6, 4`:\n     - Element `3`: Update `min` to `3`, `mini` to `10`.\n     - Element `5`: Update `max` to `5`, `maxi` to `8`.\n   - Add indices `10` and `8` to `ind`.\n   - Calculate average: `(3 + 5) / 2.0 = 4.0`.\n   - Return `4.0` to `minimumAverage`.\n\n2. Compare returned value `4.0` with `min` (`3.5`), keep `min` as `3.5`.\n\n### Fifth Iteration\n\n1. Call `help` with the array and `ind` containing `[1, 5, 0, 7, 6, 4, 10, 8]`.\n\n   **Inside `help`**:\n   - Initialize `min` to `51` and `max` to `0`.\n   - Iterate through the array, skipping indices `1, 5, 0, 7, 6, 4, 10, 8`:\n     - Element `3`: Update `min` to `3`, `mini` to `9`.\n     - Element `5`: Update `max` to `5`, `maxi` to `11`.\n   - Add indices `9` and `11` to `ind`.\n   - Calculate average: `(3 + 5) / 2.0 = 4.0`.\n   - Return `4.0` to `minimumAverage`.\n\n2. Compare returned value `4.0` with `min` (`3.5`), keep `min` as `3.5`.\n\n### Final Result\n\n- The `minimumAverage` method returns the smallest average found, which is `3.5`.\n\n\n# Complexity\n\n- **Time Complexity**: O(n^2)\n  - Due to the nested iteration structure (`n/2` times outer loop and O(n) inner loop in `help`).\n\n- **Space Complexity**: O(n)\n  - Dominated by the `ind` ArrayList which can store up to `n` indices.\n\n\n
['C++', 'Java']