5 Lines Code ||  DP || Easy C++ || Beats 100% ✅✅
Approach\n Describe your approach to solving the problem. \nWe have to remove three numbers from 3 minimum + 3 maximum but which three elements will we choose..
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to **remove three number**s from **3 minimum + 3 maximum** but which three elements will we **choose**.........\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\nHere I used **dp concept** to select three elements so as to **reduce the difference**.\n\n**Note:- Same Problem with Same Approach**\nLink:-https://leetcode.com/problems/minimum-score-by-changing-two-elements/solutions/3872837/5-lines-code-dp-easy-c-beats-100/\n\n# Complexity\n- Time complexity:O(N * Log(N))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(vector<int> arr,int i,int j,int k)\n    {\n      if(k==3) return arr[j]-arr[i];\n      return min(solve(arr,i+1,j,k+1),solve(arr,i,j-1,k+1));\n    }\n    int minDifference(vector<int>& arr) {\n        if(arr.size()<=4) return 0;\n        sort(arr.begin(),arr.end());\n        return solve(arr,0,arr.size()-1,0);\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/91d77801-4b91-43b0-bc6c-ab31349d92b8_1691318316.38075.jpeg)\n
['Array', 'Dynamic Programming', 'C++']