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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-value-of-k-coins-from-piles | Python 3 || 9 lines, recursion || T/S: 78% / 91% | python-3-9-lines-recursion-ts-78-91-by-s-yqw4 | \nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n \n @lru_cache(None)\n def dfs(coins, moves):\n | Spaulding_ | NORMAL | 2023-04-15T16:53:34.275882+00:00 | 2024-06-13T02:07:17.653179+00:00 | 238 | false | ```\nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n \n @lru_cache(None)\n def dfs(coins, moves):\n if len(piles) == coins: return 0\n\n ans, curr, pile = dfs(coins+1, moves), 0, piles[coins]\n\n for j in range(min(len(pile),... | 8 | 0 | ['Python3'] | 0 |
maximum-value-of-k-coins-from-piles | [GoLang] Recursive -> Mem Optimised DP | golang-recursive-mem-optimised-dp-by-dko-wi0d | Intuition\nWe need to find a Min/Max of something in an array/matrix => It\'s a Dynamic Programming problem (rarely a Greedy problem).\n\n# Approach - Simple re | dkochetov | NORMAL | 2023-04-15T11:06:30.517421+00:00 | 2023-04-15T16:27:29.415061+00:00 | 159 | false | # Intuition\nWe need to find a Min/Max of something in an array/matrix => It\'s a Dynamic Programming problem (rarely a Greedy problem).\n\n# Approach - Simple recursive function\nDon\'t try to write a final optimized code from the start, it will break your mind. Always start with defining a recursive function:\n\n`rec... | 8 | 0 | ['Array', 'Dynamic Programming', 'Recursion', 'Matrix', 'Go'] | 0 |
maximum-value-of-k-coins-from-piles | ✅C++ || EASY DP (Recursive + Memoization) | c-easy-dp-recursive-memoization-by-chiik-61ht | Code\n\nclass Solution {\n #define ll long long\npublic:\n int c(vector<vector<int>>& p,int i,int k,vector<vector<int>>&dp){\n if(k==0)return 0;\n | CHIIKUU | NORMAL | 2023-04-15T08:08:52.057511+00:00 | 2023-04-15T08:08:52.057542+00:00 | 1,021 | false | # Code\n```\nclass Solution {\n #define ll long long\npublic:\n int c(vector<vector<int>>& p,int i,int k,vector<vector<int>>&dp){\n if(k==0)return 0;\n if(i>=p.size())return 0;\n if(dp[i][k]!=-1)return dp[i][k];\n int ans=0;\n int mx=c(p,i+1,k,dp);\n for(int j=0;j<p[i].si... | 7 | 1 | ['Dynamic Programming', 'Prefix Sum', 'C++'] | 6 |
maximum-value-of-k-coins-from-piles | C++ | Memoization | c-memoization-by-vaibhavshekhawat-hxxi | ```\nvector> dp;\n int func(vector>& p,int i,int k){\n if(i==p.size()) return 0;\n if(dp[i][k]!=-1) return dp[i][k];\n int ans=func(p,i+ | vaibhavshekhawat | NORMAL | 2022-03-27T04:02:48.906995+00:00 | 2022-03-27T04:04:22.675569+00:00 | 620 | false | ```\nvector<vector<int>> dp;\n int func(vector<vector<int>>& p,int i,int k){\n if(i==p.size()) return 0;\n if(dp[i][k]!=-1) return dp[i][k];\n int ans=func(p,i+1,k);\n int a=0;\n for(int j=0;j<p[i].size()&&j<k;j++){\n a+=p[i][j];\n ans=max(ans,a+func(p,i+1,k-j... | 7 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
maximum-value-of-k-coins-from-piles | [Java] Bottom Up DP | java-bottom-up-dp-by-nihalanim9-ei1k | \nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n = piles.size();\n int[][] ans = new int[n+1][2001]; | nihalanim9 | NORMAL | 2022-03-27T04:01:09.007094+00:00 | 2022-03-27T04:01:09.007139+00:00 | 972 | false | ```\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n = piles.size();\n int[][] ans = new int[n+1][2001];\n Collections.sort(piles, (List<Integer> a, List<Integer> b) -> b.size() - a.size());\n for(int i = 1; i <= k; i++) {\n for(int j ... | 7 | 0 | ['Dynamic Programming', 'Java'] | 1 |
maximum-value-of-k-coins-from-piles | 🏆SPACE OPTIMISED - 💯TABULATION - ✅MEMOIZATION - ❗️RECURSION | space-optimised-tabulation-memoization-r-e16j | Intuition\nThe problem is to maximize the sum of k coins collected from n piles of coins, where each pile has a different number of coins. The constraint is tha | bose_aritra2003 | NORMAL | 2023-04-15T05:25:28.359962+00:00 | 2023-04-15T05:42:23.106219+00:00 | 369 | false | # Intuition\nThe problem is to maximize the sum of k coins collected from n piles of coins, where each pile has a different number of coins. The constraint is that you can only take coins from the top of each pile. The given solution uses a depth-first search (DFS) approach to explore all possible choices of taking coi... | 6 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 1 |
maximum-value-of-k-coins-from-piles | Easy || C++ || DP | easy-c-dp-by-amankatiyar783597-yr6s | Intuition\nSome point that are directly hit to mind.\nif we take piles[i][j] coin we need to take all the coins above index j in that i pile.\n\nfrom above we c | amankatiyar783597 | NORMAL | 2023-04-15T04:13:23.046312+00:00 | 2023-04-15T04:13:23.046340+00:00 | 1,469 | false | # Intuition\nSome point that are directly hit to mind.\n`if we take piles[i][j] coin we need to take all the coins above index j in that i pile.`\n\n`from above we can conlude that instead of taking one by one coin from a given row we take in bunch`\n\n# Approach\n\n`TRY ALL POSSIBLE WAYS`\n\n`To take bunch of coins we... | 6 | 2 | ['C++'] | 1 |
maximum-value-of-k-coins-from-piles | C++ RECURSION + TOP-DOWN | c-recursion-top-down-by-abhishek26149-s57u | // recursion \n\nint solve(vector<vector<int>>& arr,int i,int k,int n){\n if (k==0 || i==n)\n {\n return 0;\n }\n int ans=0;\n for (int j | Abhishek26149 | NORMAL | 2022-10-24T08:22:32.359178+00:00 | 2022-10-24T08:30:01.670916+00:00 | 651 | false | // recursion \n```\nint solve(vector<vector<int>>& arr,int i,int k,int n){\n if (k==0 || i==n)\n {\n return 0;\n }\n int ans=0;\n for (int j = 0; j <=k; j++)\n {\n if (arr[i].size()>=j)\n {\n if(j==0){\n ans=max(ans,solve(arr,i+1,k,n)) ;\n }\n ... | 6 | 0 | ['Recursion', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | Prefix-Sum + Bottom-up dp. DETAILED EXPLANATION. [C++/Python] | prefix-sum-bottom-up-dp-detailed-explana-89bx | \n\n# Code\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n = piles.size();\n // total n piles a | tryingall | NORMAL | 2023-04-15T00:39:12.486349+00:00 | 2023-04-15T00:45:10.211104+00:00 | 1,676 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n = piles.size();\n // total n piles and k coins we can choose.\n // so for any dp[i][j] it will store the max coins we\n // get using i piles and j coins used.\n vector<vect... | 5 | 0 | ['Prefix Sum', 'Python', 'C++', 'Python3'] | 2 |
maximum-value-of-k-coins-from-piles | [Java] Knapsack variation | Dynammic Programming | Easy to undestand, | java-knapsack-variation-dynammic-program-k676 | TC - O(N*M) \nn=size of piles,\nm=size of piles[i]\n\nclass Solution {\n public int helper(List> piles,int idx,int k,int [][]dp){\n \n if(idx<0 | Princearya23 | NORMAL | 2022-05-21T09:16:49.909698+00:00 | 2022-05-21T09:16:49.909736+00:00 | 475 | false | TC - O(N*M) \nn=size of piles,\nm=size of piles[i]\n\nclass Solution {\n public int helper(List<List<Integer>> piles,int idx,int k,int [][]dp){\n \n if(idx<0 || k == 0) return 0;\n if(dp[idx][k] != -1) return dp[idx][k];\n \n \n // exclude case \n int exclude = helper(pil... | 5 | 0 | ['Array', 'Dynamic Programming', 'Memoization', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | Recursion to Space Optimized DP | Java explained solution | Easy to understand | recursion-to-space-optimized-dp-java-exp-tvjm | \nThis question is a variation of 0/1 Unbounded Knapsack. Here we are allowed to pick coins any no. of times with 2 included constraints. \n- These picking up o | imkashyap | NORMAL | 2022-03-31T19:21:38.717134+00:00 | 2022-03-31T19:25:43.716393+00:00 | 468 | false | \nThis question is a variation of 0/1 Unbounded Knapsack. Here we are allowed to pick coins any no. of times with 2 included constraints. \n- These picking up of coins from a particular pile cannot exceed k\n- The coins in a particular pile are of different denomination\n\nIf these two constraints are removed the quest... | 5 | 0 | ['Dynamic Programming', 'Recursion', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | [CPP] DP (Recursive Approach) | Easy to Understand | cpp-dp-recursive-approach-easy-to-unders-kf4t | Explantion: The problem is similar to knapsack\'s dp solution, where everything all boils down to select / not select current value. Similary In this problem we | nishit130 | NORMAL | 2022-03-27T04:34:58.353581+00:00 | 2022-10-10T14:22:13.072695+00:00 | 395 | false | **Explantion**: The problem is similar to knapsack\'s dp solution, where everything all boils down to select / not select current value. Similary In this problem we traverse pile by pile (denoted by `i`) and for every value in pile (`j`) we select (add `pile[i][j]` to our wallet) or we move to next pile (`i+1`). For Me... | 5 | 0 | ['Dynamic Programming', 'Recursion', 'C', 'C++'] | 2 |
maximum-value-of-k-coins-from-piles | [Java] Top Down DP | java-top-down-dp-by-crimsonalien17-qc4u | Logic\nYou have n piles\nSo you can take from ith pile min = 0 coins and atmost max(sizeOf(pile), k) \nWe can do it with dynamic programming using dp table\n\n\ | CrimsonAlien17 | NORMAL | 2022-03-27T04:04:36.528008+00:00 | 2022-03-27T04:04:36.528037+00:00 | 531 | false | **Logic**\nYou have n piles\nSo you can take from `ith` pile min = 0 coins and atmost max(sizeOf(pile), k) \nWe can do it with dynamic programming using dp table\n\n\n```\nclass Solution {\n Integer dp[][]; // store state\n private int solve(List<List<Integer>>piles, int i, int k){\n // if i < 0 there are ... | 5 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 1 |
maximum-value-of-k-coins-from-piles | 💥Runtime beats 100.00%, Memory beats 84.38% [EXPLAINED] | runtime-beats-10000-memory-beats-8438-ex-vt8y | \n# Intuition\nYou have several piles of coins, and you need to select exactly k coins in total from these piles to maximize their combined value. Each pile all | r9n | NORMAL | 2024-09-19T19:45:33.367218+00:00 | 2024-09-19T19:45:33.367239+00:00 | 24 | false | \n# Intuition\nYou have several piles of coins, and you need to select exactly k coins in total from these piles to maximize their combined value. Each pile allows you to only pick coins from the top.\n\n\n# Approach\nDynamic Programming (DP) Array: Think of it like a big list where each position represents the maximum... | 4 | 0 | ['C#'] | 0 |
maximum-value-of-k-coins-from-piles | C++ || MEMOIZATION || DP || EASY TO UNDERSTNAD | c-memoization-dp-easy-to-understnad-by-y-j0ji | \nclass Solution {\npublic:\n int solve(vector<vector<int>> &v,vector<vector<int>> &dp,int s,int k,int &n){\n if(s>=n)return 0;\n if(k==0)retur | yash___sharma_ | NORMAL | 2023-04-15T05:20:38.442126+00:00 | 2023-04-15T05:20:38.442154+00:00 | 1,130 | false | ````\nclass Solution {\npublic:\n int solve(vector<vector<int>> &v,vector<vector<int>> &dp,int s,int k,int &n){\n if(s>=n)return 0;\n if(k==0)return 0;\n if(dp[s][k] != -1)return dp[s][k];\n int mx = solve(v,dp,s+1,k,n);\n int cur = 0;\n for(int i = 0; i < v[s].size(); i++){... | 4 | 1 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++'] | 1 |
maximum-value-of-k-coins-from-piles | Basic Approach (Java) (DP) | basic-approach-java-dp-by-may51936-23oc | Code\n\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n //dp[i][j] means when we just use the first i piles and j | may51936 | NORMAL | 2023-04-15T03:58:38.599478+00:00 | 2023-04-15T03:58:38.599516+00:00 | 479 | false | # Code\n```\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n //dp[i][j] means when we just use the first i piles and j picks, the maximum coins we can get\n int[][] dp = new int[piles.size()+1][k+1];\n for (int i = 1; i <= piles.size(); i++){\n for ... | 4 | 0 | ['Dynamic Programming', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | Easy to Understand | Python | Logically Explained | DP | easy-to-understand-python-logically-expl-gwci | Pre-Requisites - 0/1 Knapsack\n\nSolution -\nLet\'s do some ground work first.\nFor all the piles we can make them into prefix sum arrays\neg:- [2, 7, 3] -> [0, | Naman777 | NORMAL | 2023-04-15T03:17:21.710713+00:00 | 2023-04-15T03:48:45.191949+00:00 | 434 | false | **Pre-Requisites - 0/1 Knapsack**\n\n**Solution -**\nLet\'s do some ground work first.\nFor all the piles we can make them into prefix sum arrays\neg:- [2, 7, 3] -> [0, 2, 9, 12]\nNow the question is not how many of elements of each array to take rather which element of each prefix sum array to take.\nAlso, we can asso... | 4 | 0 | ['Dynamic Programming', 'Python'] | 0 |
maximum-value-of-k-coins-from-piles | python3 Solution | python3-solution-by-motaharozzaman1996-0hkz | \n\nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n \n @functools.lru_cache(None)\n def dp(i,K):\n | Motaharozzaman1996 | NORMAL | 2023-04-15T02:54:21.753560+00:00 | 2023-04-15T02:54:21.753591+00:00 | 974 | false | \n```\nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n \n @functools.lru_cache(None)\n def dp(i,K):\n if k==0 or i==len(piles):\n return 0\n\n res,cur=dp(i+1,K),0\n\n for j in range(min(len(piles[i]),K)):\n ... | 4 | 0 | ['Python', 'Python3'] | 0 |
maximum-value-of-k-coins-from-piles | Easy Understanding DP + Memoziation Solution | easy-understanding-dp-memoziation-soluti-99rm | UPVOTE IF YOU LIKE THE SOLUTION.\n\nclass Solution {\npublic:\n //memoization Solution\n int helper(int i, vector<vector<int>>& piles, int k, vector<vecto | singhalPratham | NORMAL | 2022-10-09T19:58:22.575911+00:00 | 2022-10-13T17:07:01.743371+00:00 | 330 | false | UPVOTE IF YOU LIKE THE SOLUTION.\n```\nclass Solution {\npublic:\n //memoization Solution\n int helper(int i, vector<vector<int>>& piles, int k, vector<vector<int>>& dp){\n //base condition\n if(i == piles.size() || k <= 0){\n return 0;\n }\n \n //check if this condit... | 4 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C'] | 0 |
maximum-value-of-k-coins-from-piles | [Python] Explained with diagram, Iterative DP solution, (Beats 98% TC) | python-explained-with-diagram-iterative-bllx6 | Worst Case time complexity = O(nk^2)\n\nIntuition* - Let\'s say we are standing at pile[i] and have already computed piles<i. And we have calculated the maximum | captain_vince | NORMAL | 2022-09-02T19:14:07.143943+00:00 | 2022-09-03T06:09:00.505689+00:00 | 371 | false | Worst Case time complexity = O(n*k^2)\n\n**Intuition** - Let\'s say we are standing at pile[i] and have already computed piles<i. And we have calculated the maximum possible sum of r (0<r<=k) number of coins uptill pile[i]. Now to calculate maximum possible sum using pile[i] following steps can be followed:-\n1) maxim... | 4 | 0 | ['Dynamic Programming', 'Python'] | 0 |
maximum-value-of-k-coins-from-piles | DP - Memoization (well explained) C++ | dp-memoization-well-explained-c-by-gunja-zjwo | The main idea here is to use Dynamic programming and I have used prefix sum to get the total sum of the top elements uptil the index where I am standing at any | gunjan10 | NORMAL | 2022-03-30T06:57:58.179249+00:00 | 2022-04-03T07:23:01.911345+00:00 | 344 | false | The main idea here is to use **Dynamic programming** and I have used **prefix sum** to get the total sum of the top elements uptil the index where I am standing at any instance.\n\nDp states are : (index , k) \n* ***index*** defines the stack which we are currently on \n* ***k*** defines the number of elements which w... | 4 | 0 | ['Dynamic Programming', 'Memoization', 'C', 'Prefix Sum'] | 1 |
maximum-value-of-k-coins-from-piles | Typescript | DP + Iterative + Beats 100.00% + Time: O(nk^2) - Space: O(k) | typescript-dp-iterative-beats-10000-time-p923 | Time: O(nk^2)\nSpace: O(k)\nLanguage: javascript, typescript\n\nRuntime: 325 ms, faster than 100.00%\nMemory Usage: 45.1 MB, less than 100.00%\n\n\nfunction max | queriel | NORMAL | 2022-03-27T06:00:24.124812+00:00 | 2022-03-27T06:18:46.128333+00:00 | 457 | false | Time: O(nk^2)\nSpace: O(k)\nLanguage: javascript, typescript\n\nRuntime: 325 ms, faster than 100.00%\nMemory Usage: 45.1 MB, less than 100.00%\n\n```\nfunction maxValueOfCoins(piles: number[][], coins: number): number {\n let dp = new Array(coins + 1).fill(0);\n \n for (let i = 0; i < piles.length; ++i) {\n\t ... | 4 | 0 | ['Dynamic Programming', 'Iterator', 'TypeScript', 'JavaScript'] | 0 |
maximum-value-of-k-coins-from-piles | [C++ Solution] Simple solution using DP | c-solution-simple-solution-using-dp-by-p-zl2d | \nclass Solution {\npublic:\n long long dp[2005][2005];\n \n int K;\n long long MaxValue(vector<vector<int>>& piles, int taken,int pile)\n {\n | pizza_slice | NORMAL | 2022-03-27T04:01:24.189650+00:00 | 2022-03-27T04:04:06.881218+00:00 | 596 | false | ```\nclass Solution {\npublic:\n long long dp[2005][2005];\n \n int K;\n long long MaxValue(vector<vector<int>>& piles, int taken,int pile)\n {\n if(taken==K) return 0;\n if(pile>=piles.size()||taken>K) return INT_MIN;\n \n if(dp[taken][pile]!=-1) return dp[taken][pile];\n ... | 4 | 1 | ['Dynamic Programming', 'Recursion', 'C'] | 0 |
maximum-value-of-k-coins-from-piles | prefix sum + 2d DP | prefix-sum-2d-dp-by-trpaslik-nbqa | Intuition\nUse DP and prefix sum\n\n# Approach\nFirst for each pile, build a prefix sum (aka cummulative sum) up to k elements (we can just trim/ignore if there | trpaslik | NORMAL | 2023-04-15T19:37:25.941494+00:00 | 2023-04-15T19:45:52.826651+00:00 | 161 | false | # Intuition\nUse DP and prefix sum\n\n# Approach\nFirst for each pile, build a prefix sum (aka cummulative sum) up to k elements (we can just trim/ignore if there is more).\n\nThen focus on the first pile.\nWe can take first coin, or two, or ... k and then deal with smaller problem (one less pile and same or less coins... | 3 | 0 | ['Dynamic Programming', 'Prefix Sum', 'Python3'] | 0 |
maximum-value-of-k-coins-from-piles | ✔💯Easy JAVA Solution ✔💯|| Dynamic Programming | easy-java-solution-dynamic-programming-b-mm7v | \n\n\n# Code\n\nclass Solution {\n int dp[][];\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n = piles.size();\n dp | HitenAgarwal | NORMAL | 2023-04-15T10:42:11.307374+00:00 | 2023-04-15T10:42:11.307408+00:00 | 163 | false | \n\n\n# Code\n```\nclass Solution {\n int dp[][];\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n = piles.size();\n dp = new int[n+1][k+1];\n for(int i =... | 3 | 0 | ['Java'] | 0 |
maximum-value-of-k-coins-from-piles | Bottom-up DP explained | bottom-up-dp-explained-by-piyush01123-rycq | We define dp[i][j] as the the answer considering 1st i piles for at most j coins. Hence final answer is dp[n][k]. In base case we consider i=0 ie considering ze | piyush01123 | NORMAL | 2023-04-15T09:38:50.191109+00:00 | 2023-04-15T09:42:55.785170+00:00 | 316 | false | We define `dp[i][j]` as the the answer considering 1st `i` piles for at most `j` coins. Hence final answer is `dp[n][k]`. In base case we consider `i=0` ie considering zero piles. This row will be just zeroes. Similarly for `j=0` column also, it will be all zeroes. \n\nConsider any general `dp[i][j]`. \n\nWe can take 0... | 3 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | C++ | Easiest Solution | Memoization | Top Down DP | Recursive | | c-easiest-solution-memoization-top-down-h0mxh | APPROACH\nI have two option\nOption 1: I will not anything from the current ith pile\nOption 2: I wiil take some coins the from current ith pile and rest from o | rafikulalam2000off | NORMAL | 2023-04-15T09:25:11.225653+00:00 | 2023-04-15T09:25:11.225700+00:00 | 376 | false | **APPROACH**\n**I have two option**\n**Option 1: I will not anything from the current ith pile**\n**Option 2: I wiil take some coins the from current ith pile and rest from other piles**\n```\nclass Solution\n{\n public:\n int dp[1001][2001];\n int solver(vector<vector < int>> &arr, int coins, int idx=0)\n... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C'] | 0 |
maximum-value-of-k-coins-from-piles | Rust, DP, concise. | rust-dp-concise-by-dfomin-132c | Intuition\nThis is dynamic programming task. The only tricky part is to find subtask.\nThe subtask is to solve it for smaller number of piles (i left most piles | dfomin | NORMAL | 2023-04-15T08:57:27.848592+00:00 | 2023-04-15T09:20:20.132692+00:00 | 217 | false | # Intuition\nThis is dynamic programming task. The only tricky part is to find subtask.\nThe subtask is to solve it for smaller number of piles (i left most piles) and for smaller k.\nOn each step we iterate over new pile for all numbers from `0` to `k` and search for best value of `l` coins from new pile and `k - l` f... | 3 | 0 | ['Rust'] | 2 |
maximum-value-of-k-coins-from-piles | C++ || Dynamic Programming | c-dynamic-programming-by-sosuke23-ufft | Code\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n = piles.size();\n \n int dp[n+1][k+ | Sosuke23 | NORMAL | 2023-04-15T02:01:13.967103+00:00 | 2023-04-15T02:01:13.967136+00:00 | 681 | false | # Code\n```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n = piles.size();\n \n int dp[n+1][k+1];\n memset(dp,0,sizeof(dp));\n\n for(int i=1; i<=n; i++)\n {\n int sz = piles[i-1].size();\n for(int j=1; j<=k... | 3 | 0 | ['Dynamic Programming', 'C++'] | 2 |
maximum-value-of-k-coins-from-piles | 🗓️ Daily LeetCoding Challenge April, Day 15 | daily-leetcoding-challenge-april-day-15-kpwje | This problem is the Daily LeetCoding Challenge for April, Day 15. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2023-04-15T00:00:17.614482+00:00 | 2023-04-15T00:00:17.614538+00:00 | 3,060 | false | This problem is the Daily LeetCoding Challenge for April, Day 15.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cre... | 3 | 0 | [] | 11 |
maximum-value-of-k-coins-from-piles | [Java/C++/Python]O(n)time/BEATS 99.97% MEMORY/SPEED 0ms APRIL 2022 | javacpythonontimebeats-9997-memoryspeed-c411b | Java\n\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n=piles.size();\n int[] dp=new int[k+1];// k st | darian-catalin-cucer | NORMAL | 2022-04-24T06:59:23.603686+00:00 | 2022-04-24T08:12:43.868196+00:00 | 478 | false | ***Java***\n```\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int n=piles.size();\n int[] dp=new int[k+1];// k steps dynamic programming;\n // for each pile to do dp.\n for(List<Integer> pile:piles){\n //use prefix sum to record each pile\... | 3 | 0 | ['C', 'Combinatorics', 'Python', 'C++', 'Java'] | 3 |
maximum-value-of-k-coins-from-piles | C++ | 2D - DP | c-2d-dp-by-archit-bikram-dpim | \nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& P, int k) {\n int m = P.size();\n for(int i = 0 ; i< m ; i++){\n | Archit-Bikram | NORMAL | 2022-03-27T04:59:49.568460+00:00 | 2022-03-27T05:08:10.999955+00:00 | 214 | false | ```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& P, int k) {\n int m = P.size();\n for(int i = 0 ; i< m ; i++){\n int n = P[i].size();\n for(int j = 1 ; j<n; ++j){\n P[i][j] += P[i][j-1];\n }\n }// sum of value if we take j... | 3 | 0 | [] | 1 |
maximum-value-of-k-coins-from-piles | Greedy Fails||Dynamic Programming (front partition)!!! | greedy-failsdynamic-programming-front-pa-bxrp | Intuition\nsince we have to take starting few of the elements so can do like take starting 1 or 2 or 3 upto the length number of elements from current pile an | ankii09102003 | NORMAL | 2024-08-26T05:40:48.734419+00:00 | 2024-08-26T05:40:48.734458+00:00 | 98 | false | # Intuition\nsince we have to take starting few of the elements so can do like take starting 1 or 2 or 3 upto the length number of elements from current pile and in each case apply a call of dp with a guide that take the elements from next pile \nalso, prefix sum can be calculated but not beneficial as it would take... | 2 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | C++ || Memoization || easy to understand | c-memoization-easy-to-understand-by-anki-2tov | \n\n# Code\n\nclass Solution {\npublic:\n int helper(vector<vector<int>>& piles, int k, int ind, vector<vector<int>> & dp){\n if(ind<0)return 0;\n | ankitkr23 | NORMAL | 2023-05-19T23:24:27.487124+00:00 | 2023-05-19T23:24:27.487157+00:00 | 11 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int helper(vector<vector<int>>& piles, int k, int ind, vector<vector<int>> & dp){\n if(ind<0)return 0;\n if(k==0)return 0;\n if(dp[ind][k]!=-1)return dp[ind][k];\n int a=helper(piles, k, ind-1, dp);\n \n int ans=a;\n for(in... | 2 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Python short and clean. Recursive. DP. Functional programming. | python-short-and-clean-recursive-dp-func-fne4 | Complexity\n- Time complexity: O(m * k)\n\n- Space complexity: O(m)\n\nwhere,\nm is number of total coins from all piles\n\n# Code\npython\nclass Solution:\n | darshan-as | NORMAL | 2023-04-15T20:04:34.675564+00:00 | 2023-04-15T20:04:34.675613+00:00 | 65 | false | # Complexity\n- Time complexity: $$O(m * k)$$\n\n- Space complexity: $$O(m)$$\n\nwhere,\n`m is number of total coins from all piles`\n\n# Code\n```python\nclass Solution:\n def maxValueOfCoins(self, piles: list[list[int]], k_: int) -> int:\n prefix_piles = [list(accumulate(p, initial=0)) for p in piles]\n\n ... | 2 | 0 | ['Array', 'Dynamic Programming', 'Prefix Sum', 'Python', 'Python3'] | 0 |
maximum-value-of-k-coins-from-piles | C++ || Recursion + Memoization | c-recursion-memoization-by-jillchaudhary-r2c4 | \n\n# Code\n\nclass Solution {\npublic:\n int dp[1001][2001];\n int fun(int i, int k, vector<vector<int>> &v, int n, vector<vector<int>> &pre){\n i | jillchaudhary39 | NORMAL | 2023-04-15T15:37:51.782112+00:00 | 2023-04-15T15:37:51.782152+00:00 | 10 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int dp[1001][2001];\n int fun(int i, int k, vector<vector<int>> &v, int n, vector<vector<int>> &pre){\n if(i>=n || k==0) return 0;\n if(dp[i][k]!=-1) return dp[i][k];\n int maxi=-1;\n for(int p=0;p<=min(k,(int)v[i].size());p++){\n ... | 2 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | C++ | Recursion + DP | c-recursion-dp-by-__priyanshu-g6nd | Code\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n \n vector<vector<int>> dp(piles.size(), vector<i | __priyanshu__ | NORMAL | 2023-04-15T13:59:18.660107+00:00 | 2023-04-15T13:59:38.799876+00:00 | 83 | false | # Code\n```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n \n vector<vector<int>> dp(piles.size(), vector<int> (k + 1, -1));\n return helper(piles, 0, k, dp);\n }\n\n int helper(vector<vector<int>> &piles, int i, int k, vector<vector<int>> &dp)\n ... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | Ruby: prefix sum and recursion | ruby-prefix-sum-and-recursion-by-lacross-l1ox | Code\nruby\nclass Array\n def scan(st) = map { st = yield st, _1 }\n def prefsum = scan(0, &:+).unshift(0)\nend\n\ndef max_value_of_coins(piles, k)\n @pile_p | lacrosse | NORMAL | 2023-04-15T11:48:19.082690+00:00 | 2023-04-15T11:48:19.082729+00:00 | 140 | false | # Code\n```ruby\nclass Array\n def scan(st) = map { st = yield st, _1 }\n def prefsum = scan(0, &:+).unshift(0)\nend\n\ndef max_value_of_coins(piles, k)\n @pile_prefs = piles.map(&:prefsum)\n @size_prefs = piles.map(&:size).prefsum\n @_dp = Array.new(piles.size) { [] } << -> _ { 0 }\n dp(0, k)\nend\n\ndef dp(i, k... | 2 | 0 | ['Recursion', 'Prefix Sum', 'Ruby'] | 0 |
maximum-value-of-k-coins-from-piles | [Kotlin] Prefix Sum DP Solution | kotlin-prefix-sum-dp-solution-by-devle79-km5y | Approach\n Describe your approach to solving the problem. \n\nUse top-down dp to find max value of coin.\n\nSave every optimal value in dp table and use that va | devle79 | NORMAL | 2023-04-15T10:30:47.576528+00:00 | 2023-04-15T10:30:47.576565+00:00 | 34 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n\nUse top-down dp to find max value of coin.\n\nSave every optimal value in dp table and use that value at next iteration.\n\nFlow goes like this:\n\n\n {\n if (index == n or k | priyanshu11_ | NORMAL | 2023-04-15T09:53:19.642415+00:00 | 2023-04-15T09:53:19.642453+00:00 | 90 | false | \n\n# Code\n```\nclass Solution\n{\npublic:\n int sumi(int index, vector<vector<int>> &piles, int k, int n, vector<vector<int>> &dp)\n {\n if (index == n or k == 0)\n return 0;\n if (dp[index][k] != -1)\n return dp[index][k];\n int notPick = sumi(index + 1, piles, k, n, dp);\n int pick = 0, coin... | 2 | 0 | ['Array', 'Dynamic Programming', 'C++', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | Solution in C++ | solution-in-c-by-ashish_madhup-1bab | 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 | ashish_madhup | NORMAL | 2023-04-15T06:07:08.563294+00:00 | 2023-04-15T06:07:08.563332+00:00 | 42 | 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)$$ --... | 2 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | PYTHON || easy solution with explanation || recursion with caching | python-easy-solution-with-explanation-re-2gli | Intuition\n Describe your first thoughts on how to solve this problem. \ndynamic programming problem \n# Approach\n Describe your approach to solving the proble | bohaa | NORMAL | 2023-04-15T03:20:18.330965+00:00 | 2023-04-15T03:22:31.393917+00:00 | 430 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ndynamic programming problem \n# Approach\n<!-- Describe your approach to solving the problem. -->\n- we first skip all nodes to start from last assume i have 4 piles (try last piles , then try 3rd and last pile , etc)\n- with base case if... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3'] | 1 |
maximum-value-of-k-coins-from-piles | C++ Simple (Recursion + Memorization) | c-simple-recursion-memorization-by-haris-gwnx | Approach\n Describe your approach to solving the problem. \n1. For each pile we add top coins ans so for any dp[i][k] it will store the max coins we can get fro | HarishRa9a | NORMAL | 2023-04-15T00:45:04.172375+00:00 | 2023-05-25T17:23:02.528187+00:00 | 26 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. For each pile we add top coins ans so for any dp[i][k] it will store the max coins we can get from ith pile using k coins.\n2. For a pile we can either choose 0,1,....k coins and then proceede toward next pile.\n# Complexity\n- Time complexity: O(n... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | DP isn't scary dude | dp-isnt-scary-dude-by-imprayas12-lls0 | \nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n /*\n -> Pick the first coin from the pile and move to next.\n | imprayas12 | NORMAL | 2022-09-29T08:38:12.607023+00:00 | 2022-09-29T08:38:12.607065+00:00 | 168 | false | ```\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n /*\n -> Pick the first coin from the pile and move to next.\n -> Don\'t pick the first coin from pile and move to next.\n -> Pick first coin and stay on the same pile to pick the next coin.\n */ \n i... | 2 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | ✔ C++ Solution | DP | O(m * k) Time | O(k) Space | c-solution-dp-om-k-time-ok-space-by-saty-4co7 | Time Complexity : O(m * k)\nSpace Complexity : O(k)\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n vector<i | satyam2001 | NORMAL | 2022-09-03T06:57:34.259500+00:00 | 2022-09-03T06:57:34.259529+00:00 | 214 | false | `Time Complexity` : `O(m * k)`\n`Space Complexity` : `O(k)`\n```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n vector<int> dp(k + 1, 0);\n for(auto& pile: piles) {\n for(size_t i = k; i >= 1; i--) {\n int csum = 0;\n for... | 2 | 0 | ['Dynamic Programming', 'C'] | 0 |
maximum-value-of-k-coins-from-piles | Recursive 3d dP , With 2d->1d mapping reduction using hashing | recursive-3d-dp-with-2d-1d-mapping-reduc-2tqn | I kept 3 variables for a state ,\nIndex_of_pile --> which pile am i currently standing at --> [i]\nindex_in_current_pile --> which index is at the top at the | are_you_in_illusion | NORMAL | 2022-08-18T19:31:23.940514+00:00 | 2022-09-12T11:11:43.274348+00:00 | 88 | false | I kept 3 variables for a state ,\nIndex_of_pile --> which pile am i currently standing at --> [i]\nindex_in_current_pile --> which index is at the top at the moment for piles[index], --> [j]\nNo_of_purchaces_remaining ---> how many transactions do I have left with me ---> [k]\n\nDp[i][j][k] = returns me the maximum... | 2 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | C++ Top-down DP solution with Explaination | c-top-down-dp-solution-with-explaination-8996 | Intuition\nTop down dynamic programming.\n\n\nExplanation\ndp[i,k] means picking k elements from pile[i] to pile[n-1].\nWe can pick 0,1,2,3... elements from the | _limitlesspragma | NORMAL | 2022-07-01T15:49:21.928585+00:00 | 2022-07-01T15:49:21.928622+00:00 | 126 | false | **Intuition**\nTop down dynamic programming.\n\n\n**Explanation**\ndp[i,k] means picking k elements from pile[i] to pile[n-1].\nWe can pick 0,1,2,3... elements from the current pile[i] one by one.\nIt asks for the maximum total value of coins we can have,\nso we need to return max of all the options.\n\n\n**Complexity*... | 2 | 0 | ['Dynamic Programming'] | 0 |
maximum-value-of-k-coins-from-piles | 🎨 The ART of Dynamic Programming | the-art-of-dynamic-programming-by-clayto-dqwv | \uD83C\uDFA8 The ART of Dynamic Programming\n\n1. All possibilities are considered via top-down brute-force depth-first-search\n2. Remember each subproblem\'s | claytonjwong | NORMAL | 2022-04-01T00:41:06.021444+00:00 | 2022-04-01T14:10:35.018346+00:00 | 234 | false | [\uD83C\uDFA8 The ART of Dynamic Programming](https://leetcode.com/discuss/general-discussion/712010/The-ART-of-Dynamic-Programming-An-Intuitive-Approach%3A-from-Apprentice-to-Master)\n\n1. **A**ll possibilities are considered via top-down brute-force depth-first-search\n2. **R**emember each subproblem\'s optimal solu... | 2 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | C++ || 2D DP | c-2d-dp-by-pandeyji2023-4ygk | \nclass Solution {\npublic:\n \n int dp[2001][2001];\n \n int helper(int idx,vector<vector<int>>& preffix,int k){\n \n if(idx >= preff | pandeyji2023 | NORMAL | 2022-03-27T11:34:49.088687+00:00 | 2022-03-27T11:34:49.088727+00:00 | 132 | false | ```\nclass Solution {\npublic:\n \n int dp[2001][2001];\n \n int helper(int idx,vector<vector<int>>& preffix,int k){\n \n if(idx >= preffix.size() || k<=0){\n return 0;\n }\n \n if(dp[idx][k] != -1){\n return dp[idx][k];\n }\n \n ... | 2 | 0 | ['Dynamic Programming'] | 1 |
maximum-value-of-k-coins-from-piles | [C++] Simple Bottom-up DP | c-simple-bottom-up-dp-by-leetcode07-v9n0 | Solution:\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n=piles.size();\n \n // dp[i][j] | leetcode07 | NORMAL | 2022-03-27T08:47:01.700517+00:00 | 2022-03-27T08:56:59.654831+00:00 | 85 | false | Solution:\n```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n=piles.size();\n \n // dp[i][j] = maximum money after taking j coins from first i piles.\n vector<vector<int> > dp(n+1, vector<int>(k+1, -2000000000));\n \n dp[0][0]=0... | 2 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | [C++] bottom up DP | c-bottom-up-dp-by-praveenchiliveri-2cum | ```\nclass Solution {\npublic:\n int maxValueOfCoins(vector>& piles, int k) {\n int n=piles.size();\n\t\t//dp[i][j] - > maximum total value of coins u | praveenchiliveri | NORMAL | 2022-03-27T05:48:57.952912+00:00 | 2022-03-27T05:51:33.557387+00:00 | 169 | false | ```\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n=piles.size();\n\t\t//dp[i][j] - > maximum total value of coins using i piles and j coins.\n vector<vector<int>> dp(n+1,vector<int>(k+1));\n\t\t// store the prefix sum for each pile.\n for(int i=0;i<... | 2 | 0 | ['Dynamic Programming', 'Iterator'] | 1 |
maximum-value-of-k-coins-from-piles | Ignore the SC and understand the logic. | ignore-the-sc-and-understand-the-logic-b-qnit | There are only 2 ways\n1. Take :\n\tif you choose the top element there are again two possibilities \n\t1. take current element and move to next list or \n\t2. | yadavharsha50 | NORMAL | 2022-03-27T05:31:22.677300+00:00 | 2022-03-27T05:43:43.481698+00:00 | 111 | false | There are only 2 ways\n1. Take :\n\tif you choose the top element there are again two possibilities \n\t1. take current element and move to next list or \n\t2. take curr element and stand on the same list and call recursion for the next element in the same list.\n2. Not Take :\n\tjust simply move to next list.\n```\ncl... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 1 |
maximum-value-of-k-coins-from-piles | DP | C++ | dp-c-by-return_404-sed3 | Let\'s define dp[i][j] = maximum total value with j coins till i-th pile .\n\nif we take x coins from i-th pile then we need (j-x) coins till (i-1)-th pile i.e | return_404 | NORMAL | 2022-03-27T05:00:41.485729+00:00 | 2022-03-27T05:00:41.485768+00:00 | 87 | false | Let\'s define dp[i][j] = maximum total value with j coins till i-th pile .\n\nif we take x coins from i-th pile then we need (j-x) coins till (i-1)-th pile i.e dp[i-1][j-x] . \n\n```\n\nclass Solution {\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n int n=piles.size();\n int dp[n... | 2 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | ✅ C++ || 2D dp + Memoization || Easy | c-2d-dp-memoization-easy-by-yogaboi-59ig | \n1. Easy C++\n2. Line by Line Explanation with Comments.\n3. Detailed Explanation \u2705\n4. 2D dp + Memoization.\n5. Please Upvote if it helps\u2B06\uFE0F\n\n | Yogaboi | NORMAL | 2022-03-27T04:56:49.723768+00:00 | 2022-03-27T04:56:49.723800+00:00 | 144 | false | ```\n1. Easy C++\n2. Line by Line Explanation with Comments.\n3. Detailed Explanation \u2705\n4. 2D dp + Memoization.\n5. Please Upvote if it helps\u2B06\uFE0F\n```\n\n**EXPLANATION**\n* Base Case-> if piles completed or k coins taken\n* skip current pile and call recursion\n* check for current pile and call recursion ... | 2 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Java Solution Memoization | java-solution-memoization-by-piyushja1n-ivgy | \nclass Solution {\n \n Integer [][]dp;\n \n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n dp = new Integer[piles.size() + | piyushja1n | NORMAL | 2022-03-27T04:21:56.810085+00:00 | 2022-03-27T04:46:51.664281+00:00 | 144 | false | ```\nclass Solution {\n \n Integer [][]dp;\n \n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n dp = new Integer[piles.size() + 1][k + 1];\n return maxPoints(piles, piles.size() - 1, k);\n }\n \n \n private int maxPoints(List<List<Integer>>piles, int i, int k){... | 2 | 0 | ['Dynamic Programming', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | Top down approach | Python3 | Intuitive solution | top-down-approach-python3-intuitive-solu-96qt | Please UpvoteCode | Alpha2404 | NORMAL | 2025-03-12T03:09:07.167067+00:00 | 2025-03-12T03:09:07.167067+00:00 | 27 | false | # Please Upvote
# Code
```python3 []
from typing import List
from functools import lru_cache
class Solution:
def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:
n = len(piles)
prefixSums = []
for pile in piles:
cur = [0]
for coin in pile:
... | 1 | 0 | ['Array', 'Dynamic Programming', 'Memoization', 'Prefix Sum', 'Python3'] | 0 |
maximum-value-of-k-coins-from-piles | Easy DP approach | easy-dp-approach-by-twasim-uz2z | 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 | twasim | NORMAL | 2024-06-28T08:42:53.064591+00:00 | 2024-06-28T08:42:53.064635+00:00 | 4 | 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(k*n)\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', 'Prefix Sum', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | Java Clean Dp Solution | java-clean-dp-solution-by-shree_govind_j-v9yv | Code\n\nclass Solution {\n private int solveMemo(List<List<Integer>> piles, int idx, int k, int[][] dp) {\n // Base case\n if (idx >= piles.siz | Shree_Govind_Jee | NORMAL | 2024-02-10T03:11:34.476164+00:00 | 2024-02-10T03:11:34.476184+00:00 | 125 | false | # Code\n```\nclass Solution {\n private int solveMemo(List<List<Integer>> piles, int idx, int k, int[][] dp) {\n // Base case\n if (idx >= piles.size() || k <= 0) {\n return 0;\n }\n\n // step-2 =>if dp[idx][k] is calculated just return it..\n if (dp[idx][k] != -1) {\n ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'Prefix Sum', 'Java'] | 0 |
maximum-value-of-k-coins-from-piles | DP | dp-by-recursive45-gmbv | Code\n\nclass Solution {\npublic:\n int solve(int r, vector<vector<int>> &piles, int k, vector<vector<int>> &dp)\n{\n if (r == piles.size())\n {\n | Recursive45 | NORMAL | 2023-08-12T02:57:55.814772+00:00 | 2023-08-12T02:57:55.814809+00:00 | 50 | false | # Code\n```\nclass Solution {\npublic:\n int solve(int r, vector<vector<int>> &piles, int k, vector<vector<int>> &dp)\n{\n if (r == piles.size())\n {\n if(k == 0)\n {\n return 0;\n }\n return -1e9;\n }\n \n if(dp[r][k] != -1)\n {\n return dp[r][k];\n ... | 1 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Ex-Amazon explains solution with a video, Python, JavaScript, Java and C++ | ex-amazon-explains-solution-with-a-video-888z | My youtube channel - KeetCode(Ex-Amazon)\nI create 154 videos for leetcode questions as of April 21, 2023. I believe my channel helps you prepare for the coming | niits | NORMAL | 2023-04-21T05:09:57.990276+00:00 | 2023-04-21T05:09:57.990299+00:00 | 48 | false | # My youtube channel - KeetCode(Ex-Amazon)\nI create 154 videos for leetcode questions as of April 21, 2023. I believe my channel helps you prepare for the coming technical interviews. Please subscribe my channel!\n\n### Please subscribe my channel - KeetCode(Ex-Amazon) from here.\n\n**I created a video for this questi... | 1 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 0 |
maximum-value-of-k-coins-from-piles | [Python] Divid and Conquer without DP, 100% | python-divid-and-conquer-without-dp-100-ur7op | Idea\nCreate a helper function getValues(s, e) that returns a vector vals. \nvals[i] stores the maximum value that you can get from picking i coins from piles s | pongpong99 | NORMAL | 2023-04-17T07:38:29.039045+00:00 | 2023-04-17T07:38:29.039079+00:00 | 17 | false | #### Idea\nCreate a helper function getValues(s, e) that returns a vector vals. \nvals[i] stores the maximum value that you can get from picking i coins from piles s, s+1, s+2, ..., e.\nWith the helper fucntion, the final result will be geValues(1, n)[k].\n\nThe basic case of getValues is when s equal to t. In this cas... | 1 | 0 | ['Divide and Conquer', 'Python'] | 0 |
maximum-value-of-k-coins-from-piles | DP Solution | Easy to Understand | Step by Step Explanation | C++ | dp-solution-easy-to-understand-step-by-s-tfzk | Intuition\n \nIt\'s obvious that there is no greedy solution for this problem since there are multiple combinations and also restriction of picking topmost of p | f_in_the_chat | NORMAL | 2023-04-15T20:39:30.495188+00:00 | 2023-04-15T20:39:30.495226+00:00 | 174 | false | # Intuition\n<!-- -->\nIt\'s obvious that there is no greedy solution for this problem since there are multiple combinations and also restriction of picking topmost of pile.\n So, we are probably going to explore all combinations and choose the most optimal one. \nThis should give a hint for a recursive complete searc... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | Easy C++ solution: recursion to memoization using prefix sum | easy-c-solution-recursion-to-memoization-b9kh | Intuition\nWe can iterate through piles and decide if we want to take something from the pile or not take it. \nIf we decide to take coins from a particular pil | itIsWhatItIs713 | NORMAL | 2023-04-15T19:45:26.522686+00:00 | 2023-04-15T19:45:26.522719+00:00 | 83 | false | # Intuition\nWe can iterate through piles and decide if we want to take something from the pile or not take it. \nIf we decide to take coins from a particular pile, then we have the choice of how many coins to take.\n\n# Approach\nLet\'s try to think of a recursive solution. \nWe have two choices, to take coins from a ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Prefix Sum', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | PHP Dynamic Programming | php-dynamic-programming-by-punkundead-3cmq | 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 | punkundead | NORMAL | 2023-04-15T19:39:42.837443+00:00 | 2023-04-15T19:39:42.837485+00:00 | 9 | 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(k * s)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(k)$$\n<!-- Add your space complexity ... | 1 | 0 | ['Dynamic Programming', 'PHP'] | 0 |
maximum-value-of-k-coins-from-piles | C++ | ✅ Top Down DP Linear Space Complexity | ✅ Bottom Up DP | c-top-down-dp-linear-space-complexity-bo-0i9y | Top Down DP linear space\n\nclass Solution {\n\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n \n int n = piles.size();\n | anxiousLeetcoder | NORMAL | 2023-04-15T17:38:07.950450+00:00 | 2023-04-15T17:38:07.950490+00:00 | 62 | false | # Top Down DP linear space\n```\nclass Solution {\n\npublic:\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n \n int n = piles.size();\n vector<int> dp(k + 1);\n dp[0] = 0;\n\n for(int j = 1; j <= k; j++)\n dp[j] = dp[j - 1] + (j - 1 < piles[n - 1].size() ? p... | 1 | 0 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Easy python solution | easy-python-solution-by-sghorai-rtf3 | \nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n presum = [list(accumulate(p, initial=0)) for p in piles]\n | sghorai | NORMAL | 2023-04-15T17:35:04.573736+00:00 | 2023-04-15T17:35:04.573786+00:00 | 81 | false | ```\nclass Solution:\n def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n presum = [list(accumulate(p, initial=0)) for p in piles]\n n = len(piles)\n dp = [[0] * (k + 1) for _ in range(n + 1)]\n for i, s in enumerate(presum, 1):\n for j in range(k + 1):\n ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Python3'] | 0 |
maximum-value-of-k-coins-from-piles | Easy C++ Dp --> Memoization Without Prefix Sum | easy-c-dp-memoization-without-prefix-sum-fuxh | 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 | Mridul2003 | NORMAL | 2023-04-15T15:59:56.226739+00:00 | 2023-04-15T15:59:56.226766+00:00 | 72 | 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 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Easy C++ Dp --> Memoization->Tabulation with Prefix Sum | easy-c-dp-memoization-tabulation-with-pr-no4e | 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 | Mridul2003 | NORMAL | 2023-04-15T15:42:14.039593+00:00 | 2023-04-15T15:58:23.093578+00:00 | 34 | 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 | ['C++'] | 0 |
maximum-value-of-k-coins-from-piles | Java || Runtime 53 ms Beats 95.6% Memory 43.1 MB Beats 82.72% | java-runtime-53-ms-beats-956-memory-431-xqmje | 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 | Akash2023 | NORMAL | 2023-04-15T15:37:33.564262+00:00 | 2023-04-15T15:37:33.564304+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)$$ --... | 1 | 0 | ['Java'] | 0 |
maximum-value-of-k-coins-from-piles | Java Solution | java-solution-by-ojus_jaiswal-cbab | \n# Code\n\nclass Solution {\n\tpublic static int maxValueOfCoins(List<List<Integer>> piles, int k) {\n\t\tint[] mv = new int[k + 1];\n\t\tint[] pileSum = new i | Ojus_Jaiswal | NORMAL | 2023-04-15T13:46:33.375045+00:00 | 2023-04-15T13:46:33.375076+00:00 | 49 | false | \n# Code\n```\nclass Solution {\n\tpublic static int maxValueOfCoins(List<List<Integer>> piles, int k) {\n\t\tint[] mv = new int[k + 1];\n\t\tint[] pileSum = new int[k + 1];\n\t\tfor (List<Integer> pile : piles) {\n\t\t\tint n = Math.min(k, pile.size());\n\t\t\tint sum = 0;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\t... | 1 | 0 | ['Java'] | 0 |
maximum-value-of-k-coins-from-piles | choose or dont choose that pile with how many are you going to choose from that pile: is the idea | choose-or-dont-choose-that-pile-with-how-aurm | \nclass Solution {\npublic:\n \n int dfs(int npile , int coins, int n,vector<vector<int>>& p,vector<vector<int>> &c)\n {\n if(npile>=n || coins | mr_stark | NORMAL | 2023-04-15T13:40:46.443265+00:00 | 2023-04-15T13:40:46.443301+00:00 | 42 | false | ```\nclass Solution {\npublic:\n \n int dfs(int npile , int coins, int n,vector<vector<int>>& p,vector<vector<int>> &c)\n {\n if(npile>=n || coins <= 0)\n return 0;\n if(c[npile][coins]!=-1)\n return c[npile][coins];\n c[npile][coins] = dfs(npile+1,coins,n,p,c);\n ... | 1 | 0 | ['C'] | 1 |
maximum-value-of-k-coins-from-piles | 2218. Maximum Value of K Coins From Piles || Java | 2218-maximum-value-of-k-coins-from-piles-si12 | \nclass Solution {\n public int solve (List<List<Integer>> piles,int i,int k,int [][] dp )\n {\n if(i>=piles.size())\n return 0;\n | ArpAry | NORMAL | 2023-04-15T12:06:13.972108+00:00 | 2023-04-15T12:06:13.972157+00:00 | 8 | false | ```\nclass Solution {\n public int solve (List<List<Integer>> piles,int i,int k,int [][] dp )\n {\n if(i>=piles.size())\n return 0;\n if(dp[i][k]!=-1)\n return dp[i][k];\n int max=0;\n max=Math.max(max,solve(piles,i+1,k,dp));\n for(int j=0;j<piles.get(i... | 1 | 0 | [] | 0 |
maximum-value-of-k-coins-from-piles | c++ | take and notTake dp | memoization | simple and easy to understand | c-take-and-nottake-dp-memoization-simple-2ssn | Complexity\n- Time complexity:\no(nk)\n\n- Space complexity:\no(nk)\n\n# Code\n\nclass Solution {\nprivate:\n int solve(int ind, vector<vector<int>>& piles, | jatinwatts | NORMAL | 2023-04-15T11:59:56.534055+00:00 | 2023-04-15T11:59:56.534095+00:00 | 35 | false | # Complexity\n- Time complexity:\no(n*k)\n\n- Space complexity:\no(n*k)\n\n# Code\n```\nclass Solution {\nprivate:\n int solve(int ind, vector<vector<int>>& piles, vector<vector<int>>& dp, int k) {\n if(ind >= piles.size()) return 0;\n\n if(dp[ind][k] != -1) return dp[ind][k];\n\n int sum = 0, t... | 1 | 0 | ['C++'] | 1 |
maximum-value-of-k-coins-from-piles | C#: DP, Recursion | c-dp-recursion-by-igor0-sn3s | Intuition\nUse DP and recursion.\n\n# Approach\nCreate the method\n\nprivate int MaxValueOfCoins((int index, int k) key, Dictionary<(int index, int k), int> dic | igor0 | NORMAL | 2023-04-15T10:23:43.232498+00:00 | 2023-04-15T10:23:43.232545+00:00 | 89 | false | # Intuition\nUse DP and recursion.\n\n# Approach\nCreate the method\n```\nprivate int MaxValueOfCoins((int index, int k) key, Dictionary<(int index, int k), int> dic, IList<IList<int>> piles)\n```\n, where\n- (int index, int k) key contains the index of a current pile and k - the number of coins\n- Dictionary<(int inde... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'C#'] | 0 |
maximum-value-of-k-coins-from-piles | No-brainer DFS solution with cache | no-brainer-dfs-solution-with-cache-by-je-xtp2 | Intuition\nIntuition 1: for pile i, I can pick l = 0, 1, ..., min(k, len(pile[i])) coins from pile i;\nIntuition 2: when I pick l coins on pile i, I then can pi | jennitheric | NORMAL | 2023-04-15T09:58:41.299721+00:00 | 2023-04-15T10:04:19.992794+00:00 | 97 | false | # Intuition\nIntuition 1: for pile i, I can pick l = 0, 1, ..., min(k, len(pile[i])) coins from pile i;\nIntuition 2: when I pick l coins on pile i, I then can pick k-l coins from i+1 to N-1 piles.\n \n# Approach\nSolve a subproblem: Find the maximum total value if we are picking from ith pile upto (N-1)th pile ... | 1 | 0 | ['Python3'] | 0 |
maximum-value-of-k-coins-from-piles | C++ || Memoization || Tabulation | c-memoization-tabulation-by-rounak_25-f1wj | Memoization Code\n\nclass Solution {\npublic:\nint dp[1001][2001];\nint solve(vector<vector<int>> &piles, int idx, int k)\n{\n if (k == 0)\n return 0; | Rounak_25 | NORMAL | 2023-04-15T09:47:21.053275+00:00 | 2023-06-16T14:56:04.743450+00:00 | 128 | false | # Memoization Code\n```\nclass Solution {\npublic:\nint dp[1001][2001];\nint solve(vector<vector<int>> &piles, int idx, int k)\n{\n if (k == 0)\n return 0;\n if (idx >= piles.size())\n return 0;\n if (dp[idx][k] != -1)\n return dp[idx][k];\n\n int ans = INT_MIN;\n int s = 0;\n int... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Prefix Sum', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | Maximum Value of K Coins From Piles C# | maximum-value-of-k-coins-from-piles-c-by-qf6e | 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 | MaddiSwetha | NORMAL | 2023-04-15T09:40:16.100165+00:00 | 2023-04-15T09:40:16.100209+00:00 | 48 | 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 | ['C#'] | 0 |
maximum-value-of-k-coins-from-piles | Ruby || recursion + memoization | ruby-recursion-memoization-by-alecn2002-jwcx | Intuition\nTry (1..k) from the first pile and calculate max for the rest with new k = k - tried, and so on\n\n# Approach\nReworked translation to Ruby of aryan_ | alecn2002 | NORMAL | 2023-04-15T09:25:32.214576+00:00 | 2023-04-15T09:25:32.214634+00:00 | 46 | false | # Intuition\nTry (1..k) from the first pile and calculate max for the rest with new k = k - tried, and so on\n\n# Approach\nReworked translation to Ruby of [aryan_0077 C++ solution](https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/solutions/3417959/image-explanation-top-down-dp-easy-concise-c-java-pyth... | 1 | 0 | ['Recursion', 'Memoization', 'Ruby'] | 0 |
maximum-value-of-k-coins-from-piles | Prefix Sum + DP | C++ | prefix-sum-dp-c-by-tusharbhart-96w7 | \nclass Solution {\n int dfs(int i, int k, int n, vector<vector<int>> &piles, vector<vector<int>> &dp) {\n if(!k || i == n) return 0;\n if(dp[i | TusharBhart | NORMAL | 2023-04-15T08:43:19.708378+00:00 | 2023-04-15T08:43:19.708407+00:00 | 20 | false | ```\nclass Solution {\n int dfs(int i, int k, int n, vector<vector<int>> &piles, vector<vector<int>> &dp) {\n if(!k || i == n) return 0;\n if(dp[i][k] != -1) return dp[i][k];\n\n int ans = 0;\n for(int j=0; j<min((int)piles[i].size(), k); j++) {\n int notpick = dfs(i + 1, k, n,... | 1 | 0 | ['Dynamic Programming', 'Memoization', 'Prefix Sum', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy - Compare Left and Right Distances | easy-compare-left-and-right-distances-by-m4xn | Intuition\nSince the task is to return the lexicographically smallest string, so we will try to convert the beginning characters into \'a\', if possible.\n\n# A | AdityaRaj_cpp | NORMAL | 2024-04-07T05:18:40.146884+00:00 | 2024-04-07T14:16:01.536865+00:00 | 2,638 | false | # Intuition\nSince the task is to return the lexicographically smallest string, so we will try to convert the beginning characters into \'a\', if possible.\n\n# Approach\n1. It iterates through each character`ch`in the input string`s`.\n3. For each character`ch`, it calculates two values:\n\u2022 `left` : The distance ... | 36 | 0 | ['String', 'Greedy', 'C++'] | 7 |
lexicographically-smallest-string-after-operations-with-constraint | Short and Sweet | short-and-sweet-by-votrubac-t7t6 | Our strategy is to change characters to a left-to-right, while we can.\n\nWe first calculate how many operations we need to change it to a: \n- dist_a = min(s[i | votrubac | NORMAL | 2024-04-07T05:35:43.980996+00:00 | 2024-04-07T17:58:37.621670+00:00 | 692 | false | Our strategy is to change characters to `a` left-to-right, while we can.\n\nWe first calculate how many operations we need to change it to `a`: \n- `dist_a = min(s[i] - \'a\', \'z\' - s[i] + 1)`.\n\nIf we have enough operations left (`dist_a <= k`), we change the character to `a`, and subtract `dist_a` from `k`.\n\nIf ... | 29 | 0 | ['C'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | Simple java solution | simple-java-solution-by-siddhant_1602-boqt | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n public String getSmallestString(String s, int k) {\n S | Siddhant_1602 | NORMAL | 2024-04-07T04:04:05.032165+00:00 | 2024-04-07T04:04:05.032198+00:00 | 871 | false | # Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n public String getSmallestString(String s, int k) {\n StringBuilder nm=new StringBuilder();\n for(int i=0;i<s.length();i++)\n {\n char c=s.charAt(i);\n in... | 17 | 0 | ['Java'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | Simple Video Solution with TC: O(26*N)->O(N) 🔥 | simple-video-solution-with-tc-o26n-on-by-zvly | Easy Video Solution\n\nhttps://youtu.be/qr_2aqMARWE\n\n# Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans= | ayushnemmaniwar12 | NORMAL | 2024-04-07T04:05:08.572979+00:00 | 2024-04-07T07:48:59.201799+00:00 | 950 | false | # Easy Video Solution\n\nhttps://youtu.be/qr_2aqMARWE\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans="";\n int n=s.size();\n for(int i=0;i<n;i++) {\n int f=0;\n for(char ch=\'a\';ch<=\'z\';ch++) {\n int d1... | 16 | 0 | ['Math', 'String Matching', 'C++'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | Python 3 || 9 lines, w/ explanation || T/S: 99% / 93% | python-3-9-lines-w-explanation-ts-99-93-ioafe | Here\'s the plan:\n\n1. We iterate across the ords of the characters in s.\n\n1. If the value of k is sufficient, we move each character of s to a along the sho | Spaulding_ | NORMAL | 2024-04-07T20:03:07.659093+00:00 | 2024-05-24T18:38:28.532668+00:00 | 219 | false | Here\'s the plan:\n\n1. We iterate across the *ords* of the characters in `s`.\n\n1. If the value of `k` is sufficient, we move each character of `s` to *a* along the shortest path for that character and decrement `k` accordingly.\n1. If the value of `k` is not sufficient, we spend all of `k` to move a character as far... | 14 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Beats 100% of users with c++ || O(26*N)❌O(N)✅ | beats-100-of-users-with-c-o26non-by-vebz-gmyq | Intuition\nThe idea is to check if it\'s possible for result[i] to be \'a\'\n(for each index i)\n\n# Approach\nLet res be the result string (of same length)\n\n | vebzb | NORMAL | 2024-04-07T05:56:53.424752+00:00 | 2024-04-07T05:56:53.424771+00:00 | 274 | false | # Intuition\nThe idea is to check if it\'s possible for result[i] to be \'a\'\n(for each index *i*)\n\n# Approach\nLet res be the result string (of same length)\n\n For each index i:\n if(distance(s[i],\'a\')<=k): \n res[i]=\'a\'\n k-=distance(s[i],\'a\')<=k\n else\n r... | 11 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java - Compare left and right distances | java-compare-left-and-right-distances-by-3tsv | Intuition\n Describe your first thoughts on how to solve this problem. \n- For each character, check if the left side distance or the right side distance is sma | makubex74 | NORMAL | 2024-04-07T04:15:00.012455+00:00 | 2024-04-08T06:11:45.109288+00:00 | 294 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- For each character, check if the left side distance or the right side distance is smaller and update accordingly.\n- If you\'re able to move to character `\'a\'` in less than `k` steps, then directly set that character to `\'a\'` and de... | 7 | 0 | ['Java'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | Easy 🔥🔥 Python 🐍 // Java // Python3 // C++ 🔥🔥 Explained 💀☠️ Beats 💯 | easy-python-java-python3-c-explained-bea-6ewj | Intuition\n\n\n\n\n\n\n\n Describe your first thoughts on how to solve this problem. \nC++ []\nclass Solution {\npublic:\n string getSmallestString(string s, | Edwards310 | NORMAL | 2024-04-07T04:02:42.442309+00:00 | 2024-04-11T08:27:40.741872+00:00 | 169 | false | # Intuition\n\n\n\n\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to minimize the distance between a string s and another string t through character changes. ... | 7 | 1 | ['String', 'C++'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | C++ || O(N) | c-on-by-abhay5349singh-4ope | Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n convert most significant chars within available moves to lowest char poo | abhay5349singh | NORMAL | 2024-04-07T04:02:44.695787+00:00 | 2024-04-07T04:02:44.695818+00:00 | 427 | false | **Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* convert most significant chars within available moves to lowest char poosible\n* next_idx = (idx+cur_k)%26; => possible char after shifting in forward direction\n* prev_idx = (idx-cur_k+26)%26; => possible char after shifti... | 6 | 0 | [] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | EASY C++ SOLUTION 🚀🔥 || SIMPLE FORCE APPROACHWITH DRY RUN ✅ | easy-c-solution-simple-force-approachwit-zbiv | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Initialize a string | _cupcake | NORMAL | 2024-04-07T04:54:47.710829+00:00 | 2024-04-07T04:54:47.710851+00:00 | 411 | 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. Initialize a string t with the same characters as string s.\n2. Iterate over each character in string s.\n3. For each character, iterate over the lowercase English ... | 5 | 0 | ['String', 'Greedy', 'C++'] | 4 |
lexicographically-smallest-string-after-operations-with-constraint | Java | C++ | Greedy Approach | Distance of Characters | T(N)= O(N*26) | java-c-greedy-approach-distance-of-chara-prip | Intuition\nFor each character in string we try all letters from \'a\' to \'z\', selecting the first one as which has less or equal distance to k\n\n# Approach\n | niveshpritmani | NORMAL | 2024-04-07T04:40:42.158854+00:00 | 2024-04-07T04:40:42.158875+00:00 | 298 | false | # Intuition\nFor each character in string we try all letters from \'a\' to \'z\', selecting the first one as which has less or equal distance to k\n\n# Approach\n### Distance Function (distance(char s1, char s2))\n\nThis function calculates the distance between two characters `s1` and `s2`. It considers the characters ... | 5 | 0 | ['String', 'Greedy', 'C++', 'Java'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | Easy C++ Solution | easy-c-solution-by-ishajangir2002-c41b | \n# Intuition\nTo find the smallest lexicographically string, we need to start from the beginning of the given string s and convert characters to \'a\' if it re | ishajangir2002 | NORMAL | 2024-04-07T11:35:18.922577+00:00 | 2024-04-07T11:35:18.922642+00:00 | 42 | false | \n# Intuition\nTo find the smallest lexicographically string, we need to start from the beginning of the given string s and convert characters to \'a\' if it reduces the overall lexicographical value. We do this until we exhaust the available operations k.\n\n# Approach\n- We iterate through each character of the strin... | 4 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅Easy | Beats 100% | Begineer Friendly | Explained💯 | easy-beats-100-begineer-friendly-explain-kzxv | # Intuition \n\n\n\n\n\n# Complexity\n- Time complexity:O(n)\n\n\n- Space complexity: O(1)\n\n\n# Code\n\npython []\nclass Solution:\n def getSmallestStrin | viresh_dev | NORMAL | 2024-04-07T04:27:55.613551+00:00 | 2024-04-07T04:36:52.077649+00:00 | 615 | 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)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space comple... | 4 | 0 | ['String', 'Greedy', 'Python3'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | BEAT 100% CPP Code | beat-100-cpp-code-by-rtik-eg14 | Intuition\n1. First take a string of same size of s as "aaaa...n"\n2. Then traverse the string s if s[i]==t[i] continue\n3. Calculate the direct distance and r | rtik | NORMAL | 2024-04-09T05:42:41.789305+00:00 | 2024-04-09T05:51:54.420114+00:00 | 205 | false | # Intuition\n1. First take a string of same size of s as "aaaa...n"\n2. Then traverse the string s if s[i]==t[i] continue\n3. Calculate the direct distance and reverse distance between "a" or t[i] and s[i] and take minimum of them.\n4. Check if this is smaller than k then we are unable to make "a" so we take character... | 3 | 0 | ['C++'] | 3 |
lexicographically-smallest-string-after-operations-with-constraint | Short 2 Step Greedy approach | short-2-step-greedy-approach-by-supermom-y6kt | Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy approach will help here as a lexicographically ordered string will ideally start | SuperMom | NORMAL | 2024-04-07T21:30:26.211411+00:00 | 2024-04-09T07:04:20.953523+00:00 | 89 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy approach will help here as a lexicographically ordered string will ideally start with the first character which is a. The key is to find minimum offset distance to character \'a\'.\n\n\n# Approach\n1. since the alphabets are cyclic... | 3 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅ Beats 100 % || Time O(n) || Space O(n) || Java - 0 ms || Easy Explained ✅ | beats-100-time-on-space-on-java-0-ms-eas-w0ic | \n# Intuition\nThe problem requires us to create the lexicographically smallest string of length k by using the characters from the given string s. To achieve t | 0xsonu | NORMAL | 2024-04-07T06:03:18.139459+00:00 | 2024-04-07T06:03:18.139476+00:00 | 117 | false | \n# Intuition\nThe problem requires us to create the lexicographically smallest string of length `k` by using the characters from the given string `s`. To achieve this, we need to manipulate the characters ... | 3 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅Very easy & Simple Approach💯||🔥2 Examples✅|| Just rephrase the Problem ||✅Compare distance to 'a' | very-easy-simple-approach2-examples-just-oc76 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem at first may look critical. But it is not. We are given an integer \'k\' th | priyankarkoley | NORMAL | 2024-04-07T05:25:16.876556+00:00 | 2024-04-07T05:34:26.491812+00:00 | 89 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem at first may look critical. But it is not. We are given an integer \'k\' that is the ***"maximum"*** distance between answer and original string \'s\'. You have to return a string that is lexicographically smallest.\n\nIt can ... | 3 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python Easy Greedy Solution!! | python-easy-greedy-solution-by-kevinliu0-gh1f | Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Code\n\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\ | kevinliu0905 | NORMAL | 2024-04-07T04:14:56.108639+00:00 | 2024-04-07T04:14:56.108666+00:00 | 254 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Code\n```\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n res_list = []\n count = 0\n dic = [\'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\', \'h\', \'i\', \'j\', \'k\', \'l\', \'m\',... | 3 | 0 | ['Python3'] | 2 |
lexicographically-smallest-string-after-operations-with-constraint | 100% beats | simple approach | 100-beats-simple-approach-by-sparker_724-zc5v | Approach\nJust check how small the current character can be made.\nIt can be made \'a\' in every step except at the last step where it may or may not be made \' | Sparker_7242 | NORMAL | 2024-04-07T04:07:20.481979+00:00 | 2024-04-07T04:07:20.482013+00:00 | 24 | false | # Approach\nJust check how small the current character can be made.\nIt can be made \'a\' in every step except at the last step where it may or may not be made \'a\' and then you run out of k operations\n\n# Complexity\n- Time complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(stri... | 3 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Short and intuitive greedy method: TC(26n) + SC(1) | short-and-intuitive-greedy-method-tc26n-j32it | Complexity\n- Time complexity: O(26n)\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# | timchen10001 | NORMAL | 2024-04-07T04:04:42.018199+00:00 | 2024-04-07T04:30:18.650510+00:00 | 184 | false | # Complexity\n- Time complexity: O(26n)\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 string getSmallestString(string s, int k) {\n int n = s.size();\n for (int i = 0... | 3 | 0 | ['Greedy', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.