Very easy DP Code || Intuitive || Explained
Complexity\n- Time complexity: O(n + 2626) \n\n- Space complexity: O(2626) \n\n# Code\n\nclass Solution {\n    int solve(int i, int j, int k, vector<int>& arr, 
# Complexity\n- Time complexity: $$O(n + 26*26)$$ \n\n- Space complexity: $$O(26*26)$$ \n\n# Code\n```\nclass Solution {\n    int solve(int i, int j, int k, vector<int>& arr, vector<vector<int>>& dp)\n    {\n        if(i == j || arr[j] - arr[i] <= k) //base case\n            return 0;\n        \n        if(dp[i][j] != -1) { //memoization step\n            return dp[i][j];\n        }\n        \n        int front = arr[i] + solve(i+1,j,k,arr,dp); //remove all from the start\n        int back = (arr[j]-arr[i]-k) + solve(i,j-1,k,arr,dp); //or remove required from the end\n        return dp[i][j] = min(front,back); //take minimum of both the cases\n    }\npublic:\n    int minimumDeletions(string word, int k) {\n        unordered_map<int,int> m;\n        //count frequency of each character\n        for(auto it : word) {\n            m[it]++;\n        }\n        \n        vector<int> arr;\n        for(auto [key,val] : m) {\n            arr.push_back(val);\n        }\n        sort(arr.begin(),arr.end()); //sort the frequency\n        int n = arr.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1)); //make dp array\n       return solve(0,arr.size()-1,k,arr,dp);\n    }\n};\n```
['Dynamic Programming', 'C++']