question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
minimum-cost-to-equalize-array | Formula based on sum and max of nums | formula-based-on-sum-and-max-of-nums-by-tgghh | Approach
First, we find the maximum element and calculate required increments
We implement a cost optimization strategy:
If 2×cost1 ≤ cost2: use only single in | ivangnilomedov | NORMAL | 2024-12-18T20:08:02.121526+00:00 | 2024-12-18T20:08:02.121526+00:00 | 15 | false | # Approach\n1. First, we find the maximum element and calculate required increments\n2. We implement a cost optimization strategy:\n - If 2\xD7cost1 \u2264 cost2: use only single increments\n - Otherwise: explore efficient combinations of paired and single increments\n3. The `relax` function explores different targ... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | Greedy + Enumeration | greedy-enumeration-by-up41guy-59lj | Thanks to Lee\'s answer\n\njavascript []\nvar minCostToEqualizeArray = function (arr, c1, c2) {\n // Find the maximum, minimum, and length of the array\n let | Cx1z0 | NORMAL | 2024-11-07T03:26:08.122238+00:00 | 2024-11-07T03:26:08.122276+00:00 | 12 | false | Thanks to [Lee\'s answer](https://leetcode.com/problems/minimum-cost-to-equalize-array/solutions/5114202/java-c-python-4-cases-o-n-solution/?envType=company&envId=microsoft&favoriteSlug=microsoft-thirty-days)\n\n```javascript []\nvar minCostToEqualizeArray = function (arr, c1, c2) {\n // Find the maximum, minimum, and... | 0 | 0 | ['Array', 'Greedy', 'Enumeration', 'JavaScript'] | 0 |
minimum-cost-to-equalize-array | Greedy + Enumeration | greedy-enumeration-by-up41guy-k2hk | Thanks to Lee\'s answer\n\njavascript []\nvar minCostToEqualizeArray = function (arr, c1, c2) {\n // Find the maximum, minimum, and length of the array\n let | Cx1z0 | NORMAL | 2024-11-07T03:24:54.591157+00:00 | 2024-11-07T03:24:54.591218+00:00 | 7 | false | Thanks to [Lee\'s answer](https://leetcode.com/problems/minimum-cost-to-equalize-array/solutions/5114202/java-c-python-4-cases-o-n-solution/?envType=company&envId=microsoft&favoriteSlug=microsoft-thirty-days)\n\n```javascript []\nvar minCostToEqualizeArray = function (arr, c1, c2) {\n // Find the maximum, minimum, and... | 0 | 0 | ['Array', 'Greedy', 'Enumeration', 'JavaScript'] | 0 |
minimum-cost-to-equalize-array | Very fast solution in Rust | very-fast-solution-in-rust-by-tapoafom-ymu1 | Intuition\nThe only intuition was to use TDD to progressively find out how it could be possible to solve this problem !\n\n# Approach\nFirst solve very simple c | tapoafom | NORMAL | 2024-09-19T16:03:18.850698+00:00 | 2024-09-19T16:03:18.850726+00:00 | 6 | false | # Intuition\nThe only intuition was to use TDD to progressively find out how it could be possible to solve this problem !\n\n# Approach\nFirst solve very simple case (eg. nums len equal 2, cost1 only, cost2 only)\nFind a solution to solve [1,3,4] :\n- Use the largest gap (1 to 4) = 3 to fill the remaining area (3 to 4)... | 0 | 0 | ['Rust'] | 0 |
minimum-cost-to-equalize-array | 💡🔧 Efficient Cost Minimization for Array Equalization in C++! 🚀✨ || Beats 100%|| | efficient-cost-minimization-for-array-eq-fxyw | Intuition\n- Determine the maximum (ma) and minimum (mi) elements in the array.\nCalculate the total sum (su) of elements in the array.\nCompute the difference | AJ_3000 | NORMAL | 2024-07-15T15:36:28.996740+00:00 | 2024-07-15T15:36:28.996773+00:00 | 13 | false | # Intuition\n- Determine the maximum (ma) and minimum (mi) elements in the array.\nCalculate the total sum (su) of elements in the array.\nCompute the difference needed to equalize the array (total).\n- Simple Cost Calculation: If the cost of two increments is less than or equal to the cost of a double operation (c1 * ... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | Best Solution || O(n) || Math || Greedy || 2ms | best-solution-on-math-greedy-2ms-by-priy-828j | \n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(1)\n | Priyanshu_pandey15 | NORMAL | 2024-06-30T17:10:01.901495+00:00 | 2024-06-30T17:10:01.901529+00:00 | 65 | false | \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code\n```\ncla... | 0 | 0 | ['Math', 'Greedy', 'Java'] | 0 |
minimum-cost-to-equalize-array | ☕ Java solution ✅ || 😼 Beats 97.13% ✨ | java-solution-beats-9713-by-barakamon-j491 | \n\n\nimport java.util.Arrays;\n\nclass Solution {\n private static final int MOD = (int) 1e9 + 7;\n\n private long calcCost(long maxDelta, long sumDelta, | Barakamon | NORMAL | 2024-06-26T12:46:59.623640+00:00 | 2024-06-26T12:46:59.623671+00:00 | 43 | false | \n\n```\nimport java.util.Arrays;\n\nclass Solution {\n private static final int MOD = (int) 1e9 + 7;\n\n private long calcCost(long maxDelta, long sumDelta, int cost1, int cost2) {\n ... | 0 | 0 | ['Java'] | 0 |
minimum-cost-to-equalize-array | My Java Code Running | my-java-code-running-by-vivekvardhan4386-dgsk | Intuition\n\nThe problem allows two types of operations:\n\n1. Increasing a single element by 1 for a cost of \'cost1\'.\n\n2. Increasing two different elements | vivekvardhan43862 | NORMAL | 2024-06-14T09:46:20.067023+00:00 | 2024-06-14T09:46:20.067082+00:00 | 34 | false | # Intuition\n\nThe problem allows two types of operations:\n\n1. Increasing a single element by 1 for a cost of **\'cost1\'**.\n\n2. Increasing two different elements each by 1 for a combined cost of **\'cost2\'**.\n\nTo minimize the total cost, we need to consider the trade-off between using the single increment opera... | 0 | 0 | ['Array', 'Greedy', 'Enumeration', 'Java'] | 0 |
minimum-cost-to-equalize-array | Minimum Cost to Equalize Array | minimum-cost-to-equalize-array-by-kenbin-6lve | Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve this problem, we aim to minimize the cost required to make all elements of the | kenbinoy | NORMAL | 2024-06-12T05:54:51.560246+00:00 | 2024-06-12T05:54:51.560282+00:00 | 21 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this problem, we aim to minimize the cost required to make all elements of the array equal. We observe that if we make all elements equal to the maximum element in the array, the cost will be minimized. However, we need to consid... | 0 | 0 | ['Java'] | 0 |
minimum-cost-to-equalize-array | Minimize Cost to Equalize Array with Single and Double Increments | minimize-cost-to-equalize-array-with-sin-vpl4 | \n\n# Intuition\nThe goal is to make all elements in the array equal with minimum cost.\nWe can increase the elements in two ways: by a single increment (with c | afonsodemello | NORMAL | 2024-06-04T14:15:43.064157+00:00 | 2024-06-04T14:15:43.064181+00:00 | 26 | false | \n\n# Intuition\nThe goal is to make all elements in the array equal with minimum cost.\nWe can increase the elements in two ways: by a single increment (with cost c1) or by a double increment (with cost c2).\nWe need to determine the optimal combination of single and double increments to minimize the total cost.\n# Ap... | 0 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 0 |
minimum-cost-to-equalize-array | Intutive solution | intutive-solution-by-bhanu_pratap5-derz | Intuition\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 | bhanu_pratap5 | NORMAL | 2024-05-17T19:16:20.036504+00:00 | 2024-05-17T19:16:20.036525+00:00 | 23 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | Beats 96% of people with python.. | beats-96-of-people-with-python-by-rexton-0ffx | Code\n\nclass Solution:\n def minCostToEqualizeArray(self, A: List[int], c1: int, c2: int) -> int:\n ma, mi = max(A), min(A)\n n = len(A)\n | Rexton_George_R | NORMAL | 2024-05-17T13:41:37.589503+00:00 | 2024-05-17T13:41:37.589531+00:00 | 33 | false | # Code\n```\nclass Solution:\n def minCostToEqualizeArray(self, A: List[int], c1: int, c2: int) -> int:\n ma, mi = max(A), min(A)\n n = len(A)\n mod = 10 ** 9 + 7\n total = ma * n - sum(A)\n\n # case 1\n if c1 * 2 <= c2 or n <= 2:\n return total * c1 % mod\n\n ... | 0 | 0 | ['Python3'] | 1 |
minimum-cost-to-equalize-array | Easy understanding solution in O(n) time complexity | easy-understanding-solution-in-on-time-c-034x | Intuition\nConsider that the vector nums[i] is sorted ascendingly (though not required). Try best to use operation 2 if it is more valuable.\nThe vector will be | leafok | NORMAL | 2024-05-17T05:49:00.955872+00:00 | 2024-05-17T05:49:00.955908+00:00 | 15 | false | # Intuition\nConsider that the vector nums[i] is sorted ascendingly (though not required). Try best to use operation 2 if it is more valuable.\nThe vector will be converted to the following values:\n{ maxN - gap, maxN, ..., maxN }, where 0 <= gap < n - 1\nIf gap > 0, apply the opeartion 2 will convert the vector into:\... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | 👍Runtime 106 ms Beats 68.42% of users with Go | runtime-106-ms-beats-6842-of-users-with-tvg1b | Code\n\nfunc minCostToEqualizeArray(A []int, c1, c2 int) int {\n\tmod := 1000000007\n\tn := len(A)\n\tmi, ma := A[0], A[0]\n\ttotal := 0\n\n\tfor _, a := range | pvt2024 | NORMAL | 2024-05-15T10:11:54.672576+00:00 | 2024-05-15T10:11:54.672596+00:00 | 4 | false | # Code\n```\nfunc minCostToEqualizeArray(A []int, c1, c2 int) int {\n\tmod := 1000000007\n\tn := len(A)\n\tmi, ma := A[0], A[0]\n\ttotal := 0\n\n\tfor _, a := range A {\n\t\tif a < mi {\n\t\t\tmi = a\n\t\t}\n\t\tif a > ma {\n\t\t\tma = a\n\t\t}\n\t\ttotal += a\n\t}\n\n\ttotalCost := int64(ma*n - total)\n\n\t// case 1\n... | 0 | 0 | ['Go'] | 0 |
minimum-cost-to-equalize-array | Minimum Cost To Equalize Array 🚦 Best Performing Approach using Swift | minimum-cost-to-equalize-array-best-perf-k30u | Intuition\nTo equalize all elements in the array, the goal is to minimize the cost of operations. We have two operations available: incrementing a single elemen | lebon | NORMAL | 2024-05-15T02:09:45.173861+00:00 | 2024-05-15T02:10:34.211993+00:00 | 8 | false | # Intuition\nTo equalize all elements in the array, the goal is to minimize the cost of operations. We have two operations available: incrementing a single element at a cost (`cost1`), and incrementing two different elements at a cost (`cost2`). We need to find an optimal strategy that uses these operations to achieve ... | 0 | 0 | ['Array', 'Swift'] | 0 |
minimum-cost-to-equalize-array | Greedy O(N) | greedy-on-by-1234ankitgarg-d7s1 | Intuition\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 | 1234ankitgarg | NORMAL | 2024-05-12T07:21:12.323935+00:00 | 2024-05-12T07:21:12.323962+00:00 | 23 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | Minimum Cost To Equalize Array | minimum-cost-to-equalize-array-by-user46-lx9l | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks for the minimum cost required to make all elements in the array equal | user4609eh | NORMAL | 2024-05-11T09:12:02.087642+00:00 | 2024-05-11T09:12:02.087682+00:00 | 32 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks for the minimum cost required to make all elements in the array equal by performing two types of operations: either increase a single element or increase two different elements. We need to come up with a strategy to minim... | 0 | 0 | ['Java'] | 0 |
minimum-cost-to-equalize-array | Python solution 💯 | python-solution-by-salahww-629a | Intuition\nWe need to find the minimum cost to make all array elements equal by either increasing a single element (cost1) or increasing two elements (cost2).\n | salahww | NORMAL | 2024-05-07T14:12:49.157762+00:00 | 2024-05-07T14:12:49.157786+00:00 | 13 | false | # Intuition\nWe need to find the minimum cost to make all array elements equal by either increasing a single element (cost1) or increasing two elements (cost2).\n# Approach\nFind the range of possible target values (min to max of the array).\nTry all target values and calculate the minimum cost to make all elements equ... | 0 | 0 | ['Python'] | 0 |
minimum-cost-to-equalize-array | Min Cost To equalize Array , Java Solution. Time Complexity : O(N) | min-cost-to-equalize-array-java-solution-rukp | \n\n# Code\n\nclass Solution {\n public int minCostToEqualizeArray(int[] nums, int cost1, int cost2) {\n\n int n = nums.length;\n if(n==0 | | langesicht | NORMAL | 2024-05-07T03:32:46.684882+00:00 | 2024-05-07T03:32:46.684905+00:00 | 67 | false | \n\n# Code\n```\nclass Solution {\n public int minCostToEqualizeArray(int[] nums, int cost1, int cost2) {\n\n int n = nums.length;\n if(n==0 || n==1){\n return 0;\n }\n\n int mod = 1000000007;\n long max = Long.MIN_VALUE;\n long min = Long.MAX_VALUE;\n ... | 0 | 0 | ['Java'] | 0 |
minimum-cost-to-equalize-array | Python | Bruteforce | O(n) | python-bruteforce-on-by-aryonbe-xfhd | Code\n\nimport math\nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10**9 + 7\n ma | aryonbe | NORMAL | 2024-05-06T12:04:50.036424+00:00 | 2024-05-06T12:04:50.036454+00:00 | 39 | false | # Code\n```\nimport math\nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10**9 + 7\n maxv = max(nums)\n d = [maxv-num for num in nums]\n if 2*cost1 <= cost2:\n return cost1*sum(d)%MOD\n n = len(nums)\n i... | 0 | 0 | ['Python3'] | 0 |
minimum-cost-to-equalize-array | Python | Bruteforce | O(n) | python-bruteforce-on-by-aryonbe-agvn | Code\n\nimport math\nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10**9 + 7\n ma | aryonbe | NORMAL | 2024-05-06T12:04:43.593473+00:00 | 2024-05-06T12:04:43.593501+00:00 | 19 | false | # Code\n```\nimport math\nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10**9 + 7\n maxv = max(nums)\n d = [maxv-num for num in nums]\n if 2*cost1 <= cost2:\n return cost1*sum(d)%MOD\n n = len(nums)\n i... | 0 | 0 | ['Python3'] | 0 |
minimum-cost-to-equalize-array | Go Greedy with brief explanation | go-greedy-with-brief-explanation-by-sitl-qb6c | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Find the maximum number of array\n2. Find the total difference between | sitleon | NORMAL | 2024-05-06T01:33:08.783940+00:00 | 2024-05-06T01:33:08.783961+00:00 | 30 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Find the maximum number of array\n2. Find the total difference between maximum and each number\n3. Also, find the majority difference value\n4. Iterate to find minimum cost of each targeted value, start with the existing ... | 0 | 0 | ['Greedy', 'Go'] | 0 |
minimum-cost-to-equalize-array | Easiest approach possible for this question. Human like approach! | easiest-approach-possible-for-this-quest-kpd5 | Intuition\nwe need to use cost2 as much as possible\n\n# Approach\nRead the solution with comments, they are self explanatory\n\n# Note (while reading the solut | xxfalconxx | NORMAL | 2024-05-06T00:51:32.001560+00:00 | 2024-05-06T00:51:32.001590+00:00 | 103 | false | # Intuition\nwe need to use cost2 as much as possible\n\n# Approach\nRead the solution with comments, they are self explanatory\n\n# Note (while reading the solution)\nwhen I say (i, j) I mean a c2 operation on indicies (i, j). Element at index 0 in function solveRem is always the number n. Rest are 0s because they don... | 0 | 0 | ['C++'] | 1 |
minimum-cost-to-equalize-array | [Python] All relevant preimages of cost function | python-all-relevant-preimages-of-cost-fu-txfs | Let\'s call the moves single and double. First, c2 = min(c2, 2*c1) if two single moves are cheaper than a double.\n\nSuppose the final position has every elemen | awice | NORMAL | 2024-05-05T23:39:27.605534+00:00 | 2024-05-05T23:39:27.605551+00:00 | 51 | false | Let\'s call the moves single and double. First, `c2 = min(c2, 2*c1)` if two single moves are cheaper than a double.\n\nSuppose the final position has every element equal to `height`, what will be the `cost(height)`?\n\n- Say we have a total of `volume` increments to do. If no element requires a lot of work, we could pa... | 0 | 0 | ['Python3'] | 0 |
minimum-cost-to-equalize-array | Python Hard | python-hard-by-lucasschnee-cnbt | \nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10 ** 9 + 7\n INF = 10 ** 20\n | lucasschnee | NORMAL | 2024-05-05T21:19:43.771801+00:00 | 2024-05-05T21:20:07.813876+00:00 | 22 | false | ```\nclass Solution:\n def minCostToEqualizeArray(self, nums: List[int], cost1: int, cost2: int) -> int:\n MOD = 10 ** 9 + 7\n INF = 10 ** 20\n N = len(nums)\n mx = max(nums)\n mn = min(nums)\n c1, c2 = cost1, cost2\n\n if c2 >= 2 * c1:\n return (sum(mx - n... | 0 | 0 | ['Python3'] | 0 |
minimum-cost-to-equalize-array | Clear Solution with Easy-to-Understand and Intuitive Explanation | O(N) Time and O(1) Space | clear-solution-with-easy-to-understand-a-oyau | Intuition\n Describe your first thoughts on how to solve this problem. \n\nIn this problem, we need to equalize the nums array with either single operations or | machinescholar01 | NORMAL | 2024-05-05T19:49:04.945914+00:00 | 2024-05-05T20:57:46.340718+00:00 | 34 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nIn this problem, we need to equalize the nums array with either <b>single operations</b> or <b>pair operations</b> for an amount of <b>work = max(nums) * len(nums) - sum(nums)</b>. The amount of work is due to that we can greedily solve... | 0 | 0 | ['Greedy', 'Python3'] | 0 |
minimum-cost-to-equalize-array | O(N) | 2 or 3 Case Discussion with some math. | on-2-or-3-case-discussion-with-some-math-cevz | Intuition\nSeveral case discussion and need some carefullness for each case. Can expand more details if needed. For now, I put some comments in the code.\n\n# C | popzkk | NORMAL | 2024-05-05T17:48:16.464868+00:00 | 2024-05-06T00:50:17.362092+00:00 | 53 | false | # Intuition\nSeveral case discussion and need some carefullness for each case. Can expand more details if needed. For now, I put some comments in the code.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python3\nclass Solution:\n def minCostToEqualizeArray(self, nums: Li... | 0 | 0 | ['Math', 'Greedy', 'Python3'] | 0 |
minimum-cost-to-equalize-array | Solution By Vivek Gupta || Linear Time | solution-by-vivek-gupta-linear-time-by-t-z2iv | Youtube Explaination\n\n# Code\n\nusing lli = long long int;\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) | paardarshee | NORMAL | 2024-05-05T14:17:55.328001+00:00 | 2024-05-05T14:17:55.328029+00:00 | 57 | false | [Youtube Explaination](https://www.youtube.com/live/6N_gzgld8PI?t=2254s)\n\n# Code\n```\nusing lli = long long int;\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) {\n cost2 = min(cost2,2*cost1);\n lli n = nums.size(), minVal = 1e9,maxVal = 0,sumVal=0,fi... | 0 | 0 | ['C++'] | 0 |
minimum-cost-to-equalize-array | C++ || Bruteforce + Greedy + sorting || Easy approach | c-bruteforce-greedy-sorting-easy-approac-ft5t | Intuition\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 | Yuvraj161 | NORMAL | 2024-05-05T12:39:01.581111+00:00 | 2024-05-05T12:39:01.581153+00:00 | 49 | false | # Intuition\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: O(n*logn)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n #define ll long long\n ll mod=1e9+7;\n in... | 0 | 0 | ['Array', 'Math', 'Sorting', 'C++'] | 0 |
minimum-cost-to-equalize-array | My Solution | my-solution-by-hope_ma-mima | \n/**\n * let `n` be the length of the vector `nums`\n * 1. find the maximum number `max_num`, minimum number `min_num` from the vector `nums`\n * 2. calculate | hope_ma | NORMAL | 2024-05-05T12:12:02.806274+00:00 | 2024-05-06T15:46:47.385704+00:00 | 9 | false | ```\n/**\n * let `n` be the length of the vector `nums`\n * 1. find the maximum number `max_num`, minimum number `min_num` from the vector `nums`\n * 2. calculate the sum `total` of the numbers of the vector `nums`\n * let\'s construct a vector `stones` of size `n`,\n * each element of which is (`max_num` - `num`),\n *... | 0 | 0 | [] | 0 |
minimum-cost-to-equalize-array | O(maxValue) simple solution | omaxvalue-simple-solution-by-dmitrii_bok-wdjo | Just go through all possible valuse from [maxValue, 2 * maxValue] and fast check each of them simple math\n\n int minCostToEqualizeArray(const vector<int>& n | dmitrii_bokovikov | NORMAL | 2024-05-05T11:26:12.251776+00:00 | 2024-05-05T11:30:39.444105+00:00 | 38 | false | Just go through all possible valuse from [maxValue, 2 * maxValue] and fast check each of them simple math\n```\n int minCostToEqualizeArray(const vector<int>& nums, int c1, int c2) {\n using ll = long long;\n constexpr ll MOD = 1\'000\'000\'007;\n const ll sum = accumulate(cbegin(nums), cend(num... | 0 | 0 | ['C++'] | 1 |
minimum-cost-to-equalize-array | Tricky Greedy Solution | tricky-greedy-solution-by-ritiksharma_09-ia9e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nwe use window of 4maxi due to constraint \n Describe your approach to sol | Ritiksharma_09 | NORMAL | 2024-05-05T09:42:11.861786+00:00 | 2024-05-05T09:43:28.056263+00:00 | 77 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nwe use window of 4*maxi due to constraint \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(4*MAXI)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(... | 0 | 0 | ['Greedy', 'C++'] | 0 |
minimum-cost-to-equalize-array | Just a runnable solution | just-a-runnable-solution-by-ssrlive-6xlb | \n\nimpl Solution {\n pub fn min_cost_to_equalize_array(nums: Vec<i32>, cost1: i32, cost2: i32) -> i32 {\n let nums = nums.iter().map(|&x| x as i64).c | ssrlive | NORMAL | 2024-05-05T05:56:34.591674+00:00 | 2024-05-05T05:56:34.591707+00:00 | 25 | false | \n```\nimpl Solution {\n pub fn min_cost_to_equalize_array(nums: Vec<i32>, cost1: i32, cost2: i32) -> i32 {\n let nums = nums.iter().map(|&x| x as i64).collect::<Vec<i64>>();\n let n = nums.len();\n let mut maxi = 0;\n let mut tot = 0;\n let mut mini = 1_000_000_000_i64;\n f... | 0 | 0 | ['Rust'] | 0 |
minimum-cost-to-equalize-array | JS Solution - Greedy + Math | js-solution-greedy-math-by-cutetn-ml25 | Pro tip: I LOVE JUSTINA XIE \uD83D\uDC9C\uD83D\uDC9C\uD83D\uDC9C\nYEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE | CuteTN | NORMAL | 2024-05-05T05:33:38.820150+00:00 | 2024-05-05T16:33:14.504117+00:00 | 57 | false | Pro tip: I LOVE JUSTINA XIE \uD83D\uDC9C\uD83D\uDC9C\uD83D\uDC9C\nYEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE... | 0 | 0 | ['Math', 'Greedy', 'JavaScript'] | 0 |
minimum-cost-to-equalize-array | Javascript greedy 1318ms | javascript-greedy-1318ms-by-henrychen222-b1hk | \nconst mod = 1e9 + 7, ll = BigInt, bmod = ll(mod)\n\nconst minCostToEqualizeArray = (a, b, c) => {\n b = ll(b), c = ll(c)\n let n = ll(a.length), limit = | henrychen222 | NORMAL | 2024-05-05T05:29:06.570963+00:00 | 2024-05-05T05:29:06.570979+00:00 | 24 | false | ```\nconst mod = 1e9 + 7, ll = BigInt, bmod = ll(mod)\n\nconst minCostToEqualizeArray = (a, b, c) => {\n b = ll(b), c = ll(c)\n let n = ll(a.length), limit = 0;\n for (const x of a) limit = Math.max(limit, x);\n\n let sum = 0n, max = 0n;\n for (const x of a) {\n let remove = ll(limit - x);\n ... | 0 | 0 | ['Math', 'Greedy', 'JavaScript'] | 0 |
minimum-cost-to-equalize-array | Python solution, fairly simple | python-solution-fairly-simple-by-treehou-owy7 | Intuition\nFirst sort nums. Now we\'re trying to get all the values to max(nums). Think of it as filling holes. For example if the smallest num is 3 and max is | TreeHouseCoding | NORMAL | 2024-05-05T05:25:51.104073+00:00 | 2024-05-05T06:16:35.349252+00:00 | 67 | false | # Intuition\nFirst sort nums. Now we\'re trying to get all the values to max(nums). Think of it as filling holes. For example if the smallest num is 3 and max is 10, then we need to fill 7 holes to get that to target.\n\nIf there are at least three elements in nums and the number of holes for the leftmost (smallest) nu... | 0 | 0 | ['Python3'] | 0 |
minimum-cost-to-equalize-array | java solution | java-solution-by-prakharvsrivastava-vk7t | Intuition\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 | prakharvsrivastava | NORMAL | 2024-05-05T05:13:34.986272+00:00 | 2024-05-05T05:13:34.986305+00:00 | 101 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Array', 'Java'] | 0 |
minimum-cost-to-equalize-array | [Go] Greedy algorithm (106 ms) | go-greedy-algorithm-106-ms-by-andvt-r2ej | Intuition\nhttps://leetcode.com/problems/minimum-cost-to-equalize-array/submissions/1249630464/\n\n# Approach\n Describe your approach to solving the problem. \ | AnDVT | NORMAL | 2024-05-05T04:43:26.082516+00:00 | 2024-05-05T04:43:26.082543+00:00 | 77 | false | # Intuition\nhttps://leetcode.com/problems/minimum-cost-to-equalize-array/submissions/1249630464/\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\n- Space complexity:\n<!-- Add your space complexity here,... | 0 | 0 | ['Go'] | 0 |
minimum-operations-to-make-character-frequencies-equal | It's no more hard if you read this solution | its-no-more-hard-if-you-read-this-soluti-lgvj | Intuition
Count Character Frequencies – Analyze how frequently each character appears.
Try Different Targets – Assume that the final "good" string will have cha | senorita143 | NORMAL | 2024-12-22T15:26:16.112850+00:00 | 2024-12-22T15:26:16.112850+00:00 | 1,287 | false | # Intuition
1. Count Character Frequencies – Analyze how frequently each character appears.
2. Try Different Targets – Assume that the final "good" string will have characters appearing at some uniform frequency (target).
3. Minimize Operations – For each target, calculate the minimum number of deletions/insertions nee... | 25 | 1 | ['Hash Table', 'Dynamic Programming', 'Python3'] | 8 |
minimum-operations-to-make-character-frequencies-equal | [Python] DP | python-dp-by-awice-kkdr | Count the characters and say all characters in the final string have common frequency target. Then all characters have count either 0 or target. Also, a chara | awice | NORMAL | 2024-12-15T04:46:43.451931+00:00 | 2024-12-15T04:46:43.451931+00:00 | 1,550 | false | Count the characters and say all characters in the final string have common frequency `target`. Then all characters have count either `0` or `target`. Also, a character is never moved 2 or more times, otherwise you could just delete and insert it.\n\nSo compared to only being allowed to insert/delete characters, cost... | 19 | 1 | ['Python3'] | 5 |
minimum-operations-to-make-character-frequencies-equal | Those who know 👀 | those-who-know-by-etian6795-q9nd | IntuitionTry every frequencyApproachUse DP to find the min operations to get all characters to the current frequencydp1 is min ops if previous character was del | fluffyunicorn1125 | NORMAL | 2024-12-15T04:12:12.651306+00:00 | 2024-12-15T04:23:58.672735+00:00 | 1,784 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry every frequency\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse DP to find the min operations to get all characters to the current frequency\n\ndp1 is min ops if previous character was deleted\ndp2 is min o... | 11 | 2 | ['Java'] | 1 |
minimum-operations-to-make-character-frequencies-equal | C++, brute force final good string character count | c-brute-force-final-good-string-characte-knlg | IntuitionIterate over each possible character count value in the final good string.
Let dp[j] be the number of operations to make the string good from character | chasey | NORMAL | 2024-12-15T14:31:13.415933+00:00 | 2024-12-15T14:31:13.415933+00:00 | 462 | false | # Intuition\nIterate over each possible character count value in the final good string.\nLet dp[j] be the number of operations to make the string good from character j to \'z\'.\n\nGoing backwards from \'z\' to \'a\' for each character you have three options:\n1. Remove all characters:\ndp[j] = c + dp[j+1])\n2. Make ch... | 5 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | [C++] DP Solution | c-dp-solution-by-junbinliang-il18 | Brief Idea :
We can think about the problem as we have an array of 26 piles of stones, in 1 operation you can either increase/decrease each piles by 1, or decre | junbinliang | NORMAL | 2024-12-15T04:17:44.775548+00:00 | 2024-12-15T04:21:12.006175+00:00 | 1,084 | false | Brief Idea :\n1. We can think about the problem as we have an array of 26 piles of stones, in 1 operation you can either increase/decrease each piles by 1, or decrease by 1 and increase the next pile by 1. You need to make them all euqal.\n2. There is no need to use the move to adjecent operation more than once. You on... | 5 | 0 | ['C++'] | 1 |
minimum-operations-to-make-character-frequencies-equal | Heavily Commented Code using Dynamic Programming | heavily-commented-code-using-dynamic-pro-90r9 | Well yet again I was unable to solve the 4th Question so here is the most understandable beautiful solution I could find from the leaderboard.
This solution is | LeadingTheAbyss | NORMAL | 2024-12-15T05:04:00.165521+00:00 | 2024-12-15T05:04:19.650237+00:00 | 513 | false | - Well yet again I was unable to solve the 4th Question so here is the most understandable beautiful solution I could find from the leaderboard.\n- This solution is by [h_bugw7](https://leetcode.com/u/h_bugw7/) , so all credits to them for this beautiful Solution.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n in... | 4 | 0 | ['Dynamic Programming', 'C++'] | 1 |
minimum-operations-to-make-character-frequencies-equal | O(26^2) | memoization of a recursive solution for freq balancing using an ordered map | o262-memoization-of-a-recursive-solution-23jq | Complexity
Time complexity: O(262)
Space complexity: O(263)
Code | lokeshwar777 | NORMAL | 2025-01-09T06:50:30.097702+00:00 | 2025-01-09T06:50:30.097702+00:00 | 181 | false | # Complexity
- Time complexity: $$O(26^2)$$
- Space complexity: $$O(26^3)$$
# Code
```cpp []
// curfreq-current frequency, expfreq-expected frequency,
// ulimit-upper limit, prevops- previous operations
class Solution {
private:
int freq[26];
map<tuple<int,int,int>,int>dp;
int getMinOps(int i,int expfreq... | 3 | 0 | ['Hash Table', 'String', 'Dynamic Programming', 'Recursion', 'Counting', 'C++'] | 1 |
minimum-operations-to-make-character-frequencies-equal | C++ DP Recursive & 4ms Tabulation (2 Solutions) | c-dp-recursive-tabulations-2-solutions-b-4xzq | 0ms Submission LinkDP State: [char, hasSaveFromPreviousChar]Complexity
Time complexity: O(n∗26∗2)=O(n)
Space complexity: O(1) (tabulation)
CodeVersion 1: R | bramar2 | NORMAL | 2024-12-18T09:07:59.554400+00:00 | 2024-12-18T09:11:14.884936+00:00 | 431 | false | \n[0ms Submission Link](https://leetcode.com/problems/minimum-operations-to-make-character-frequencies-equal/submissions/1481861167/)\n\n**DP State: [char, hasSaveFromPreviousChar]**\n\n# Complexity\n- Time ... | 3 | 0 | ['String', 'Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | O(n) 28 ms | on-28-ms-by-votrubac-b9du | We count characters using cnt, and consider all character frequencies within [min(cnt), max(cnt)] range.\n\n> It can be shown that we do not need to consider fr | votrubac | NORMAL | 2024-12-15T07:30:18.430488+00:00 | 2024-12-15T08:34:26.229767+00:00 | 197 | false | We count characters using `cnt`, and consider all character frequencies within `[min(cnt), max(cnt)]` range.\n\n> It can be shown that we do not need to consider frequencies outside of that range. \n\nThen, for each frequency, we can compute the minimum number of operations in a linear time (26 * 2) using take-not take... | 2 | 0 | [] | 0 |
minimum-operations-to-make-character-frequencies-equal | C++ dp memo with intuition of dp memo explanation | c-dp-memo-with-intuition-of-dp-memo-expl-wnp9 | IntuitionTry to find the optimal frequency each character should be with a loop. Use DP memo to find the amount of moves required for each frequency in O(1).For | user5976fh | NORMAL | 2024-12-15T07:07:30.171096+00:00 | 2024-12-15T07:12:26.541854+00:00 | 227 | false | # Intuition\nTry to find the optimal frequency each character should be with a loop. Use DP memo to find the amount of moves required for each frequency in O(1).\n\nFor dp memo, after taking a look at other discussion posts I figured out the logic behind why I could memoize based on current index and a boolean value re... | 2 | 0 | ['C++'] | 1 |
minimum-operations-to-make-character-frequencies-equal | BEATS 100% || Java Solution || Optimum Solution | beats-100-java-solution-optimum-solution-9io9 | Complexity
Time complexity: O(N + K)
Space complexity: O(1)
Code | yallavamsipavan1234 | NORMAL | 2024-12-15T04:57:54.265280+00:00 | 2024-12-15T04:57:54.265280+00:00 | 508 | false | # Complexity\n- Time complexity: `O(N + K)`\n\n- Space complexity: `O(1)`\n\n# Code\n```java []\nclass Solution {\n public int makeStringGood(String s) {\n char[] str = s.toCharArray();\n int n = str.length;\n int[] cnt = new int[26];\n for (char c : str) {\n cnt[c - \'a\']++;\... | 2 | 0 | ['Array', 'Math', 'String', 'Dynamic Programming', 'Greedy', 'Matrix', 'Counting', 'Java'] | 1 |
minimum-operations-to-make-character-frequencies-equal | [C++] DP | c-dp-by-projectcoder-qih6 | Let f(i, 0/1/2) represent the minimum cost when considering the first i elements and applying operation 0/1/2 (delete all/fill the deficit/transfer the excess) | projectcoder | NORMAL | 2024-12-15T06:40:07.979697+00:00 | 2024-12-15T06:40:07.979729+00:00 | 80 | false | Let f(i, 0/1/2) represent the minimum cost when considering the first i elements and applying operation 0/1/2 (delete all/fill the deficit/transfer the excess) to element i:\n\n f(i,0) = min{ f(i-1,0), f(i-1,1), f(i-1,2) } + ai\n f(i,1) = min{ f(i-1,0) + max(avg-aj-ai,0), f(i-1,1) + (avg-ai), f(i-1,2) + max(avg-(... | 1 | 0 | [] | 0 |
minimum-operations-to-make-character-frequencies-equal | How it feels working with legacy codebase... | how-it-feels-working-with-legacy-codebas-jrqk | Don\'t feel like cleaning up the code right now, but the logic is as follows:\n\nNotice we can only increment the letter, not decrement.\n\nwe can use greedy to | JJZin | NORMAL | 2024-12-15T04:26:17.923784+00:00 | 2024-12-15T04:33:29.828534+00:00 | 77 | false | Don\'t feel like cleaning up the code right now, but the logic is as follows:\n\nNotice we can only increment the letter, not decrement.\n\nwe can use greedy to compute in O(n) time if we have a predefined target\n\n\nThis is the important part: if the letter count is GREATER than predefined target, you can either remo... | 1 | 0 | [] | 0 |
minimum-operations-to-make-character-frequencies-equal | Using Bottom-up DP with TC O(26 * N) + explanation | Simple code, easy to understand! | using-bottom-up-dp-with-tc-o26-n-explana-sfm5 | Complexity
Time complexity: O(26∗n)
Space complexity: O(n)
Code | phutruonnttn | NORMAL | 2024-12-24T15:55:39.302455+00:00 | 2024-12-24T15:55:39.302455+00:00 | 54 | false | 
# Complexity
- Time complexity: $$O(26 * n)$$
- Space complexity: $$O(n)$$
# Code
```cpp []
class Solution {
public:
int makeStringGood(string s) {
int n = s.size();
vector<int> f... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | [C++] iterate through the frequency O(26*n) | c-iterate-through-the-frequency-o26n-by-w0hmh | IntuitionApproachFixed the target number per letter, and then figure out where to insert/delete/bump to meet the condition.Once the number is fixed, the 3 opera | ahimawan | NORMAL | 2024-12-15T08:43:12.466194+00:00 | 2024-12-15T08:43:12.466194+00:00 | 140 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFixed the target number per letter, and then figure out where to insert/delete/bump to meet the condition.\n\n Once the number is fixed, the 3 operations:\n 1. bump --... | 1 | 0 | ['C++'] | 2 |
minimum-operations-to-make-character-frequencies-equal | Simple O(max frequency) time and O(1) space solution 3ms | simple-omax-frequency-time-and-o1-space-mkbrs | IntuitionWe first notice that the order of the string does not matter and so we can convert it into a 26 dimensional frequency array freq. Our operations become | lovesbumblebees | NORMAL | 2024-12-15T07:03:09.225561+00:00 | 2024-12-15T07:03:09.225561+00:00 | 422 | false | # Intuition\nWe first notice that the order of the string does not matter and so we can convert it into a 26 dimensional frequency array <code>freq</code>. Our operations become fixing an index i and performing one of the following: <code>freq[i]++</code>, <code>freq[i]--</code>, <code>freq[i]--, freq[i+1]++</code>. Th... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | iterate over finally frequency of each character | iterate-over-finally-frequency-of-each-c-eohh | Intuitioniterate over finally frequency of each character,
use dp to find best way to make all characters have same frequencyApproachiterate over finally freque | c337134154 | NORMAL | 2024-12-15T06:04:59.606615+00:00 | 2024-12-15T06:04:59.606615+00:00 | 310 | false | # Intuition\niterate over finally frequency of each character,\nuse dp to find best way to make all characters have same frequency\n\n# Approach\niterate over finally frequency of each character,\nuse dp to find best way to make all characters have same frequency\n\n# Complexity\n- Time complexity:\nO(n) x 26\n\n- Spac... | 1 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP | O(N * 26) | O(26*2) DP | dp-on-26-o262-dp-by-then00bprogrammer-ff0m | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | then00bprogrammer | NORMAL | 2024-12-15T05:07:19.091188+00:00 | 2024-12-15T05:07:19.091188+00:00 | 488 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP on all possible target frequencies. | dp-on-all-possible-target-frequencies-by-4fp4 | IntuitionEvery deletion can be used to make free incrment for next character in alphabetApproachfor all possible target frequency [0,max_frequency].
dp for min | sandeep_p | NORMAL | 2024-12-15T04:49:32.973489+00:00 | 2024-12-15T06:08:33.635411+00:00 | 218 | false | # Intuition\nEvery deletion can be used to make free incrment for next character in alphabet\n\n# Approach\nfor all possible target frequency [0,max_frequency].\ndp for min cost.\ndp(i,carry)=min cost to make all chars [i,26] same freq as target.\ncarry is the number of free increments we can make( carried over from pr... | 1 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | without dp | without-dp-by-mustafaansari-fo7h | ApproachInstead of using dynamic programming with multiple variables (dp1, dp2, free), we can break the problem into simpler steps by using frequency counts and | mustafaansari | NORMAL | 2024-12-15T04:17:25.175875+00:00 | 2024-12-15T04:17:25.175875+00:00 | 241 | false | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInstead of using dynamic programming with multiple variables (dp1, dp2, free), we can break the problem into simpler steps by using frequency counts and performing operations directly on those counts. This can simplify the solution while maintaini... | 1 | 3 | ['Python3'] | 1 |
minimum-operations-to-make-character-frequencies-equal | python dp | python-dp-by-mykono-n7gj | Code | Mykono | NORMAL | 2025-02-12T04:58:14.522412+00:00 | 2025-02-12T04:58:14.522412+00:00 | 12 | false | # Code
```python3 []
class Solution:
def makeStringGood(self, s: str) -> int:
# Count frequency of each letter a-z
freq = [0] * 26
for char in s:
freq[ord(char) - ord("a")] += 1
@cache
def dp(letter_idx: int, carry: int, target: int) -> int:
# Base ca... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP | Kotlin [EXPLAINED] | dp-kotlin-explained-by-r9n-gx0c | IntuitionMake all characters in the string appear with the same frequency using the minimum number of operations. The operations allowed are inserting or removi | r9n | NORMAL | 2025-02-11T17:00:41.656148+00:00 | 2025-02-11T17:00:41.656148+00:00 | 6 | false | # Intuition
Make all characters in the string appear with the same frequency using the minimum number of operations. The operations allowed are inserting or removing characters to balance the frequencies.
# Approach
I start by counting the frequency of each character in the string. Then, I use recursion with memoizati... | 0 | 0 | ['Array', 'Hash Table', 'Math', 'Binary Search', 'Dynamic Programming', 'Memoization', 'Matrix', 'Counting', 'Kotlin'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Optimizing Character Frequencies with Recursive DP+Memo | O(26 * N) Solution | optimizing-character-frequencies-with-re-d4u1 | Intuition
Count Frequencies:
First, we count the frequency of each character in the string.
Store these frequencies in a sorted order (based on characters). | cpriyanshug00 | NORMAL | 2025-01-30T14:04:05.607763+00:00 | 2025-01-30T14:04:05.607763+00:00 | 10 | false | # Intuition
- Count Frequencies:
- First, we count the frequency of each character in the string.
Store these frequencies in a sorted order (based on characters).
Dynamic Programming + Recursion (fxn function):
- Try making every possible frequency i (from 0 to mx, the max frequency in s) the standard frequency.
Recu... | 0 | 0 | ['Hash Table', 'String', 'Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Minimum Operations to Make Character Frequencies Equal | minimum-operations-to-make-character-fre-j5nh | IntuitionApproachDynamic ProgrammingComplexity
Time complexity:O(n * 26 *2)
Space complexity:O(26 * 2)
Code | Subham_Pujari23 | NORMAL | 2025-01-17T03:57:27.065617+00:00 | 2025-01-17T03:57:27.065617+00:00 | 27 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
Dynamic Programming
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(n * 26 *2)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(26 * 2)
<!-- Add your space com... | 0 | 0 | ['Java'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Simple Java solution that beats 97% | simple-java-solution-that-beats-97-by-yu-t6ek | IntuitionApproachComplexity
Time complexity:
O(N + K)
N being length of the string
K being maximum count of a char in a stringcreating the count by char array i | yunkook | NORMAL | 2025-01-09T16:19:24.647474+00:00 | 2025-01-09T16:19:24.647474+00:00 | 41 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(N + K)
N being length of the string
K being maximum count of a char in a string
creating the count by char array is N +
calculating nu... | 0 | 0 | ['Java'] | 0 |
minimum-operations-to-make-character-frequencies-equal | C++ Working Dp Solution | c-working-dp-solution-by-learner_11-tu5o | Working Approach:\nThe task is to transform a given string into a "Good String", where all characters appear with the same frequency. This frequency can range f | Learner_11 | NORMAL | 2024-12-17T14:02:47.706423+00:00 | 2024-12-18T06:01:19.471421+00:00 | 31 | false | Working Approach:\nThe task is to transform a given string into a "Good String", where all characters appear with the same frequency. This frequency can range from 0 to n (where n is the length of the string). To determine the minimal number of operations required to make the string "Good," we identify the global minim... | 0 | 0 | ['Dynamic Programming', 'Memoization'] | 0 |
minimum-operations-to-make-character-frequencies-equal | My Solution | my-solution-by-hope_ma-keh7 | \n/**\n * Time Complexity: O(n + max_count)\n * Space Complexity: O(1)\n * where `n` is the length of the string `s`\n * `max_count` is the maximum number | hope_ma | NORMAL | 2024-12-16T07:03:10.938845+00:00 | 2024-12-16T07:03:10.938877+00:00 | 9 | false | ```\n/**\n * Time Complexity: O(n + max_count)\n * Space Complexity: O(1)\n * where `n` is the length of the string `s`\n * `max_count` is the maximum number of all letters of the string `s`\n */\nclass Solution {\n public:\n int makeStringGood(const string &s) {\n /**\n * name the following operations\n ... | 0 | 0 | [] | 0 |
minimum-operations-to-make-character-frequencies-equal | T: O(N), M: O(N) | t-on-m-on-by-vladislav_zavadski-zcpx | Iterating over all posibble amount of character occuring c . And check how many operations needed. \nCase 1: Symbol occurs c or 0 times, then do nothing, just s | vladislav_zavadski | NORMAL | 2024-12-15T14:12:23.397973+00:00 | 2024-12-15T14:22:33.505737+00:00 | 42 | false | Iterating over all posibble amount of character occuring `c` . And check how many operations needed. \nCase 1: Symbol occurs `c` or `0` times, then do nothing, just switching to the next one\nCase 2: Symbol occurs more than `c` times, then dicrease amount to `c` and pass deleted amount (`from_prev`) next (see Case 3).\... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Easy Solving | easy-solving-by-siam01f-i8eq | Let\'s break this down as simply as possible and focus on the core logic.\n\nProblem Understanding:\nWe need to balance the frequency of characters in the strin | siam01f | NORMAL | 2024-12-15T05:18:15.253599+00:00 | 2024-12-15T05:18:15.253625+00:00 | 79 | false | Let\'s break this down as simply as possible and focus on the core logic.\n\nProblem Understanding:\nWe need to balance the frequency of characters in the string s to meet a predefined target frequency. The trick is we can only add characters (increment), not remove them, but we can adjust counts as we move through the... | 0 | 0 | ['Python3'] | 1 |
minimum-operations-to-make-character-frequencies-equal | Python Hard | python-hard-by-lucasschnee-0uls | null | lucasschnee | NORMAL | 2024-12-27T17:35:23.319486+00:00 | 2024-12-27T17:42:44.266605+00:00 | 26 | false | ```
class Solution:
def makeStringGood(self, s: str) -> int:
'''
two cases:
1. all of s is the same
2. all of s is 0 or the same
leftover only carries one time, because delete + add is better for 2 or more times
'''
N = len... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP Recursive Solution | dp-recursive-solution-by-ankuraj_27-fpx2 | Code | ankuraj_27 | NORMAL | 2024-12-26T15:35:18.676070+00:00 | 2024-12-26T15:35:18.676070+00:00 | 22 | false | # Code
```cpp []
class Solution {
public:
int f(int &n,int ind,int extra,int &th,vector<int> &v,vector<vector<int>> &dp) {
if(ind==26) return 0;
if(dp[ind][extra]!=-1) return dp[ind][extra];
int mn=1e9,a=v[ind];
if(extra) {
if(v[ind]<th) {
if(v[ind-1]<=th)... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Java | DP | O(n^2) | java-dp-on2-by-aryonbe-rj2h | Code | aryonbe | NORMAL | 2024-12-24T06:03:31.374029+00:00 | 2024-12-24T06:03:31.374029+00:00 | 48 | false | # Code
```java []
class Solution {
public int makeStringGood(String s) {
int n = s.length();
int[] count = new int[26];
int[][] dp = new int[27][2];
for(int i = 0; i < n; ++i) count[s.charAt(i)-'a']++;
int res = n;
for(int target = 1; target <= n; ++target){
... | 0 | 0 | ['Java'] | 0 |
minimum-operations-to-make-character-frequencies-equal | C++ | DP | O(n^2) | c-dp-on2-by-aryonbe-sx8m | Code | aryonbe | NORMAL | 2024-12-24T05:48:55.575145+00:00 | 2024-12-24T05:48:55.575145+00:00 | 16 | false | # Code
```cpp []
class Solution {
public:
int makeStringGood(string s) {
int n = s.size();
int count[26];
int dp[27][2];
for(char c: s) count[c-'a']++;
int res = n;
for(int target = 1, mx = *max_element(count,count+26); target <= mx; target++){
dp[26][0] ... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Python | DP | O(n^2) | python-dp-on2-by-aryonbe-14f7 | Code | aryonbe | NORMAL | 2024-12-24T04:16:16.304296+00:00 | 2024-12-24T04:16:16.304296+00:00 | 21 | false | # Code
```python3 []
class Solution:
def makeStringGood(self, s: str) -> int:
count = [0]*26
for c in s:
count[ord(c)-ord('a')] += 1
@cache
def dp(i, deleted, target):
if i == 26: return 0
if count[i] == target:
return dp(i+1, 0, ta... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Key Idea Explained | key-idea-explained-by-sarthakbhandari-9b80 | Intuition
Find X such that sum(abs(X - A[i])) is minimised.
X is median of A[], this is the proof
Approach
Try all X values in [MIN_CHAR_FREQ, MAX_CHAR_FREQ] an | sarthakBhandari | NORMAL | 2024-12-22T22:52:58.652372+00:00 | 2024-12-22T22:52:58.652372+00:00 | 24 | false | **Intuition**
Find `X` such that `sum(abs(X - A[i]))` is minimised.
- `X` is median of `A[]`, this is the [proof](https://www.youtube.com/watch?v=yiZlbK_t_9o)
**Approach**
Try all `X` values in `[MIN_CHAR_FREQ, MAX_CHAR_FREQ]` and choose the best one
How to solve for particular `X`? Problem would have been quite easy... | 0 | 0 | ['Hash Table', 'String', 'Dynamic Programming', 'Greedy', 'Counting', 'Python'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Java Solution || Dynamic Programming | java-solution-dynamic-programming-by-roh-s83e | IntuitionTo make the string s "good," we need to ensure that the frequency of all characters in the string becomes equal. This is done by considering all possib | rohit-motwani1313 | NORMAL | 2024-12-22T05:33:36.749818+00:00 | 2024-12-22T05:33:36.749818+00:00 | 61 | false | # Intuition
To make the string s "good," we need to ensure that the frequency of all characters in the string becomes equal. This is done by considering all possible target frequencies (tar) from 1 to the maximum frequency of any character in the string.
For each target frequency, we calculate the minimum operations re... | 0 | 0 | ['String', 'Dynamic Programming', 'Java'] | 0 |
minimum-operations-to-make-character-frequencies-equal | easy dp solution | easy-dp-solution-by-barkaaat-m6m6 | Code | Barkaaat | NORMAL | 2024-12-21T22:14:04.651023+00:00 | 2024-12-21T22:14:04.651023+00:00 | 17 | false | # Code
```cpp []
class Solution {
public:
int dp[27][20009], vis[27][20009], k, id;
int v[27];
int solve(int i=0, int rem=0) {
if (i == 26) return rem;
int &ans=dp[i][rem];
if (vis[i][rem] == id) return ans;
vis[i][rem]=id;
ans=solve(i+1, v[i])+rem;
if (v[i] ... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | C++ Dynamic Programming With Memoization (n * 26 * 2) Complexity | c-dynamic-programming-with-memoization-n-lo7p | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | smitvavliya | NORMAL | 2024-12-20T15:05:34.607656+00:00 | 2024-12-20T15:05:34.607656+00:00 | 21 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | 4 Hour to solve it :<<, C++ | 4-hour-to-solve-it-c-by-nguyenbaphuchung-dof0 | It took me 4 hours to realize thisIntuitionAfter reading the topic, I see that there are 3 states that are suspicious of using dynamic programming. I tried comb | nguyenbaphuchung2 | NORMAL | 2024-12-20T11:34:49.860001+00:00 | 2024-12-20T11:34:49.860001+00:00 | 23 | false |
**It took me 4 hours to realize this**
--
# Intuition
------------
After reading the topic, I see that there are 3 states that are suspicious of using dynamic programming. I tried combining the case of decreasing and increasing into one, because when decreasing, it can decrease to the frequency k under consideration, ... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Minimum Operations to Make Character Frequencies Equal | minimum-operations-to-make-character-fre-1kuu | Code | Ansh1707 | NORMAL | 2024-12-20T10:39:56.905936+00:00 | 2024-12-20T10:39:56.905936+00:00 | 15 | false |
# Code
```python []
class Solution(object):
def makeStringGood(self, s):
"""
:type s: str
:rtype: int
"""
char_frequency = [0] * 26
for char in s:
char_frequency[ord(char) - 97] += 1
max_frequency = max(char_frequency)
min_operat... | 0 | 0 | ['String', 'Python'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Python DP Solution with Key Comments | python-dp-solution-following-hints-by-xi-qjob | IntuitionI did not come up with this solution on my own during the contest. I followed all the 7 hints and succeeded after some trial and error.I did peek at ot | geemaple | NORMAL | 2024-12-19T16:32:48.174639+00:00 | 2024-12-19T16:51:46.052063+00:00 | 35 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
I did not come up with this solution on my own during the contest. I followed all the 7 hints and succeeded after some trial and error.
I did peek at other contestant’s answer and knew I should use 2D DP.
# Approach
<!-- Describe your app... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Minimum Operations to Make Character Frequencies Equal | minimum-operations-to-make-character-fre-l39i | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | AryanSaraf | NORMAL | 2024-12-18T09:15:03.270273+00:00 | 2024-12-18T09:15:03.270273+00:00 | 117 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 1 |
minimum-operations-to-make-character-frequencies-equal | Optimizing String Goodness: A Dynamic Programming Adventure!" 🚀✨ | optimizing-string-goodness-a-dynamic-pro-rulv | IntuitionThe problem requires modifying the frequency of characters in a string to make it "good" under specific conditions. My first thought was to find an opt | jerryjacob09 | NORMAL | 2024-12-17T15:52:21.858619+00:00 | 2024-12-17T15:52:21.858619+00:00 | 30 | false | # Intuition \nThe problem requires modifying the frequency of characters in a string to make it "good" under specific conditions. My first thought was to find an optimal method to adjust character frequencies while minimizing the cost. Since the problem involves adjacent relationships, dynamic programming seems like a ... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP + Brute Force | Python | dp-brute-force-python-by-justinleung0204-wg0c | Intuitionquota is the number of free quotas to increase cnt[i] without extra cost(operations).At each index i, if cnt[i] has to be decreased, we always assume i | justinleung0204 | NORMAL | 2024-12-17T12:22:51.701894+00:00 | 2024-12-17T12:23:25.645144+00:00 | 45 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n$$quota$$ is the number of free quotas to increase cnt[i] without extra cost(operations). \n\nAt each index $$i$$, if $$cnt[i]$$ has to be decreased, we always assume it is a Operation 3 and save quota for $$cnt[i+1]$$ to be increase. \n\... | 0 | 0 | ['Dynamic Programming', 'Greedy', 'Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Python3 Solution | Using @cache DP --- (Upsolved after the Contest) | python3-solution-using-cache-dp-upsolved-igaf | Code | apurvdwivedi518 | NORMAL | 2024-12-16T18:30:03.363410+00:00 | 2024-12-16T18:30:03.363410+00:00 | 71 | false | # Code\n```python3 []\nclass Solution:\n def makeStringGood(self, s: str) -> int:\n freq = Counter(s)\n\n @cache\n def dfs(i, expectedOcc, leftoverChars):\n if i==26:\n return 0\n\n char=chr(i+ord(\'a\'))\n occurance=freq.get(char,0)\n\n ... | 0 | 0 | ['Hash Table', 'Dynamic Programming', 'Memoization', 'Python', 'Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | O(n * 26) | on-26-by-user9754iq-crbj | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | user9754IQ | NORMAL | 2024-12-16T05:54:40.565450+00:00 | 2024-12-16T05:54:40.565450+00:00 | 57 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | DP | O(n^1.5) time, O(n^1.5) space | Python3 | dp-on15-time-on15-space-python3-by-haris-drpw | Complexity
Time complexity: O(n1.5)
Space complexity: O(n1.5)
Code | HariShankarKarthik | NORMAL | 2024-12-16T05:30:17.001379+00:00 | 2024-12-16T05:30:17.001379+00:00 | 29 | false | # Complexity\n- Time complexity: $$O(n^{1.5})$$\n- Space complexity: $$O(n^{1.5})$$\n\n# Code\n```python3 []\nclass Solution:\n def makeStringGood(self, s: str) -> int:\n hash = [0] * 26\n for c in s:\n hash[ord(c) - ord("a")] += 1\n\n max_freq = max(hash)\n memo = [dict() for ... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | simple dp | simple-dp-by-chen3933-yxst | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | chen3933 | NORMAL | 2024-12-16T01:07:58.058695+00:00 | 2024-12-16T01:07:58.058695+00:00 | 49 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | just a variant | just-a-variant-by-igormsc-383v | Code | igormsc | NORMAL | 2024-12-15T20:06:16.385369+00:00 | 2024-12-15T20:06:16.385369+00:00 | 22 | false | # Code\n```kotlin []\nclass Solution {\n fun makeStringGood(s: String): Int =\n s.fold(IntArray(\'z\'.code + 1)) { r, c -> r[c.code]++; r }.slice(\'a\'.code..\'z\'.code).let { cnt ->\n (1..s.length).minOf { j ->\n cnt.fold(IntArray(3)) { r, c ->\n if (c >= j) intAr... | 0 | 0 | ['Kotlin'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Unique O(26^3 * log N + N) Ternary Search + DP in Python3 | unique-o263-log-n-ternary-search-dp-in-p-xfoy | IntuitionMy solution explores the number of distinct characters to use. For using k distinct characters, I apply ternary search to find the best length L, which | metaphysicalist | NORMAL | 2024-12-15T19:08:35.258789+00:00 | 2024-12-16T08:31:35.623297+00:00 | 74 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy solution explores the number of distinct characters to use. For using $k$ distinct characters, I apply ternary search to find the best length $L$, which is a multiple of $k$. \n\nTo compute the cost of $(L, k)$, a dynamic programming w... | 0 | 0 | ['Binary Search', 'Dynamic Programming', 'Memoization', 'Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Recursive O(n) DP with comments | recursive-on-dp-with-comments-by-ac12110-rikb | Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | ac121102 | NORMAL | 2024-12-15T16:35:23.875078+00:00 | 2024-12-15T16:35:23.875078+00:00 | 64 | false | # Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int work(vector<int> &freq, int &tar, int i, int gave, vector<array<int, 2>> &dp) {\n if (i == freq.size()) return 0; // Base case\n bool gv = (gave > 0);\n if (dp[i][gv] != -1) ... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Nothing to say | nothing-to-say-by-yatin2004-raqh | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | yatin2004 | NORMAL | 2024-12-15T12:17:28.503045+00:00 | 2024-12-15T12:17:28.503045+00:00 | 110 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Dp + hash table | dp-hash-table-by-maxorgus-lb2t | count s into freq - freq[i] is the frequency of the ith lettertry every target within min(freq) (non-zero) and max(freq)do the dp, for every target, at index i | MaxOrgus | NORMAL | 2024-12-15T11:26:10.862585+00:00 | 2024-12-15T11:26:10.862585+00:00 | 73 | false | count s into freq - freq[i] is the frequency of the ith letter\n\ntry every target within min(freq) (non-zero) and max(freq)\n\ndo the dp, for every target, at index i\n\nwhen freq[i] is zero, go over it\n\nelse, first try increase it to target or decrease it to zero, get the one that would cost the minimum steps.\n\n... | 0 | 0 | ['Hash Table', 'Dynamic Programming', 'Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Simple 2 understand Memorization DP solution | simple-2-understand-memorization-dp-solu-71jv | Code | user7634ri | NORMAL | 2024-12-15T11:02:30.750135+00:00 | 2024-12-15T11:02:30.750135+00:00 | 77 | false | \n\n# Code\n```cpp []\nclass Solution {\npublic:\n int recur(vector<int> & dp, vector<int> &v, int c, int i) {\n if(i == 26) {\n return 0;\n }\n\n if(dp[i] != -1) {\n return dp[i];\n }\n\n int ans = v[i] + recur(dp, v, c, i + 1);\n // basically handle i... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | C++. Brute-Force DP. Iterating over all possible occurrences. | c-brute-force-dp-iterating-over-all-poss-oak9 | Intuition
Ordering does not matter. Simply count up the characters in an array.
Try every possible occurence for each character. Thus a solution can be done | cakuang1 | NORMAL | 2024-12-15T08:55:16.382735+00:00 | 2024-12-15T08:55:16.382735+00:00 | 62 | false | # Intuition\n\n1. Ordering does not matter. Simply count up the characters in an array.\n2. Try every possible occurence for each character. Thus a solution can be done in O(26n).\n3. Now for some fixed occurrence x, we determine the minimum number of operations needed to make each character\'s occurrence x or 0.\n4. T... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | Iterating over the final frequency, use DP to count | iterating-over-the-final-frequency-use-d-qwm9 | IntuitionFor each character, we have 2 choices:
increase / decrease to the target frequency
decrease to 0
For the operation decrease, we have 2 choices:
decreas | nguyenquocthao00 | NORMAL | 2024-12-15T06:24:05.622588+00:00 | 2024-12-15T06:30:40.584476+00:00 | 62 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each character, we have 2 choices:\n- increase / decrease to the target frequency\n- decrease to 0 \n\nFor the operation decrease, we have 2 choices:\n- decrease current character\n- decrease current character, increase the next char... | 0 | 0 | ['Python3'] | 0 |
minimum-operations-to-make-character-frequencies-equal | [c++] DFS + DP + Greedy | c-dfs-dp-greedy-by-lyronly-c072 | IntuitionApproach1 similar framework as binary search (but it is not binary search), fix one dimension : frequency of each char, then caculate minimum number of | lyronly | NORMAL | 2024-12-15T06:18:14.288282+00:00 | 2024-12-15T06:35:25.372461+00:00 | 82 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1 similar framework as binary search (but it is not binary search), fix one dimension : frequency of each char, then caculate minimum number of operations based on thi... | 0 | 0 | ['C++'] | 0 |
minimum-operations-to-make-character-frequencies-equal | C# DP | c-dp-by-user8702ha-o2kg | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | user8702Ha | NORMAL | 2024-12-15T05:23:37.548965+00:00 | 2024-12-15T05:23:37.548965+00:00 | 24 | false | # Intuition\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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C#'] | 0 |
course-schedule-iv | [Java/Python] Floyd–Warshall Algorithm - Clean code - O(n^3) | javapython-floyd-warshall-algorithm-clea-9q2v | Idea\n- This problem is to check if 2 vertices are connected in directed graph. \n- Floyd-Warshall O(n^3) is an algorithm that will output the minium distance o | hiepit | NORMAL | 2020-05-30T16:01:24.436586+00:00 | 2021-09-10T02:09:33.542465+00:00 | 19,547 | false | **Idea**\n- This problem is to check if 2 vertices are connected in directed graph. \n- Floyd-Warshall `O(n^3)` is an algorithm that will output the minium distance of any vertices. We can modified it to output if any vertices is connected or not.\n\n**Complexity:**\n- Time: `O(n^3)`\n- Space: `O(n^2)`\n\n**More Floy-w... | 302 | 4 | [] | 40 |
course-schedule-iv | [Java] Topological Sorting | java-topological-sorting-by-asuka-soryu-5zyk | A -> B -> C\nC is prerequisites of B\nB is prerequisites of A\nSo when we do a topology Sort , just simply add A\'s direct prerequisite B to A and also all prer | ASUKA-Soryu | NORMAL | 2020-05-30T17:18:05.583822+00:00 | 2020-05-31T13:57:30.344798+00:00 | 11,944 | false | **A -> B -> C**\nC is prerequisites of B\nB is prerequisites of A\nSo when we do a topology Sort , just simply add A\'s direct prerequisite B to A and also all prerequisites of B to A. \nBesides this part, everything is same as course schedule I and course schedule II\n\nTopology sort can transfer the prerequisites co... | 119 | 1 | [] | 19 |
course-schedule-iv | C++ | Kahn's Algorithm | Short and simple | Explained | c-kahns-algorithm-short-and-simple-expla-ebp9 | This problem is a direct application of kahn\'s algorithm with addition to that, we need to maintain a table which represents if two courses are prerequisites o | shield75_ | NORMAL | 2021-10-22T18:12:28.101777+00:00 | 2021-10-22T18:12:28.101819+00:00 | 7,102 | false | This problem is a direct application of kahn\'s algorithm with addition to that, we need to maintain a table which represents if two courses are prerequisites of one another.\n\n1. Push all the vertices with indegree 0 to the queue.\n2. For all such vertices, decrease their adjacent vertex\'s indegree by 1 since we are... | 66 | 0 | ['Topological Sort', 'C', 'C++'] | 2 |
course-schedule-iv | Transitive closure - Floyd Warshall with detailed explaination - python ,c++, java | transitive-closure-floyd-warshall-with-d-1mha | Brute force :\n for each i th query \n start dfs from queries[i][0]\n if you reach queries[i][1] return True \n else False\n \n\n | sankethbk7777 | NORMAL | 2020-05-30T16:04:17.217352+00:00 | 2020-05-30T16:19:25.100342+00:00 | 7,583 | false | Brute force :\n for each i th query \n start dfs from queries[i][0]\n if you reach queries[i][1] return True \n else False\n \n\n\nSince there can be 10^4 queries, we cannot do dfs every time for each query to\nfind if there is a path between queries[i][0] and queries[i][1]\n\nWe must ans... | 59 | 0 | ['C', 'Python', 'Java'] | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.