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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximize-win-from-two-segments | Both 100% | C++ | 58 ms/54.6 MB | both-100-c-58-ms546-mb-by-sungod1223-0kp4 | Intuition\n Describe your first thoughts on how to solve this problem. \nLet DP[i] represent the farthest distance that can be reached to the right at position | SunGod1223 | NORMAL | 2023-02-10T18:16:33.784502+00:00 | 2023-02-10T18:19:01.716759+00:00 | 323 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet DP[i] represent the farthest distance that can be reached to the right at position i. The problem is to find x and y to maximize the sum of DP[x] + DP[y]. Note that the parts covered by x and y cannot overlap.\n\n# Approach\n<!-- Desc... | 2 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | [Binary Search + DP - With TC & SC & Approach] | binary-search-dp-with-tc-sc-approach-by-e204r | \n# Approach\n- Pick First_Range_STARTIdx from 0 till n-1\n- Now,START = prizePositions[START] , END = START + k\n- Find First_Range_ENDIdx Using Binary Search( | MSJi | NORMAL | 2023-02-05T00:11:57.806225+00:00 | 2023-02-05T18:20:35.659320+00:00 | 347 | false | \n# Approach\n- Pick First_Range_STARTIdx from 0 till n-1\n- Now,START = prizePositions[START] , END = START + k\n- Find First_Range_ENDIdx Using Binary Search(END) or UpperBound(END) as all values in range [START,END] they are Now a part of First_Range\n- Now, Second_Range_STARTIdx will either start Just from First_Ra... | 2 | 0 | ['Binary Search', 'Dynamic Programming', 'C++'] | 2 |
maximize-win-from-two-segments | Maximize (left max + right max) for every i || precomputations || O(n) | maximize-left-max-right-max-for-every-i-bjsqr | Intuition\nThe idea is that as we have to select two segments and making those segments disjoint would always be better. So lets take an index i in the array an | yash_karakoti | NORMAL | 2023-02-04T19:01:44.758983+00:00 | 2023-02-04T19:08:51.024574+00:00 | 99 | false | # Intuition\nThe idea is that as we have to select two segments and making those segments disjoint would always be better. So lets take an index i in the array and take the first segment in the left of i and the second segment in the right of i. \n\n# Approach\nMaximizing the (**left segment** + **right segments**) val... | 2 | 0 | ['Sliding Window', 'C++'] | 2 |
maximize-win-from-two-segments | Recursion + Memoization in Cpp.. | recursion-memoization-in-cpp-by-sanket_j-ni5w | \n# Code\n\nclass Solution {\npublic:\n\n int func(int i,vector<int>&p,int k,int t,vector<vector<int>>&dp){\n\n if(i>=p.size())return 0;\n if(t | Sanket_Jadhav | NORMAL | 2023-02-04T17:30:17.412402+00:00 | 2023-02-04T17:30:17.412441+00:00 | 381 | false | \n# Code\n```\nclass Solution {\npublic:\n\n int func(int i,vector<int>&p,int k,int t,vector<vector<int>>&dp){\n\n if(i>=p.size())return 0;\n if(t<=0)return 0;\n\n if(dp[i][t]!=-1)return dp[i][t];\n\n int a=0,b=0;\n\n int ind=upper_bound(p.begin(),p.end(),p[i]+k)-p.begin();\n\n ... | 2 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Python clear solution | Leetcode 2054 - Two Best Non-Overlapping Events | python-clear-solution-leetcode-2054-two-cisn2 | Clearly, maximum score will be achieved with two non-overlapping segments.\nAs a result, we can see the link of this problem to Leetcode 2054.\n\n def maximi | vincent_great | NORMAL | 2023-02-04T16:17:33.560444+00:00 | 2023-02-04T16:55:07.413348+00:00 | 1,051 | false | Clearly, maximum score will be achieved with `two non-overlapping segments`.\nAs a result, we can see the link of this problem to Leetcode 2054.\n\n def maximizeWin(self, ps: List[int], k: int) -> int:\n if max(ps)-min(ps)<=k*2:\n return len(ps)\n\n scores, q, cur, ans = [], [], 0, 0\n\t\t# ... | 2 | 0 | [] | 1 |
maximize-win-from-two-segments | Java | Two Pointer Solution | Simple & Easy Solution using Left max and Right max | java-two-pointer-solution-simple-easy-so-4snp | Code\n\nclass Solution {\n public int maximizeWin(int[] prizePositions, int k) {\n \n int n = prizePositions.length;\n int leftMax[] = n | onefineday01 | NORMAL | 2024-01-30T14:41:46.257499+00:00 | 2024-03-08T18:33:12.001341+00:00 | 86 | false | # Code\n```\nclass Solution {\n public int maximizeWin(int[] prizePositions, int k) {\n \n int n = prizePositions.length;\n int leftMax[] = new int[n];\n int rightMax[] = new int[n];\n\n leftMax[0] = 1;\n for(int i = 1, j = 0; i < n; i++) {\n while(prizePositions[... | 1 | 0 | ['Two Pointers', 'Java'] | 0 |
maximize-win-from-two-segments | Python Medium | python-medium-by-lucasschnee-0x61 | \nclass Solution:\n def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n\n N = len(prizePositions)\n\n dp = [0] * (N + 1)\n\n | lucasschnee | NORMAL | 2023-08-23T01:52:11.535157+00:00 | 2023-08-23T01:52:11.535176+00:00 | 21 | false | ```\nclass Solution:\n def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n\n N = len(prizePositions)\n\n dp = [0] * (N + 1)\n\n l = 0\n\n ans = 0\n\n for r in range(N):\n\n while prizePositions[l] + k < prizePositions[r]:\n l += 1\n\n ... | 1 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | 99% || C++ | 99-c-by-shradhaydham24-zu6m | 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 | shradhaydham24 | NORMAL | 2023-07-16T18:59:10.581959+00:00 | 2023-07-16T18:59:10.581979+00:00 | 53 | 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++'] | 1 |
maximize-win-from-two-segments | dp || similar to buy and sell stocks with 2 transaction || memoization || binary search | dp-similar-to-buy-and-sell-stocks-with-2-im2l | Intuition\n Describe your first thoughts on how to solve this problem. \nwe can use dp to find at most 2 different ranges and return the maximum sum of these ra | sarthakrautelanew | NORMAL | 2023-02-10T09:17:02.396918+00:00 | 2023-02-10T09:17:39.672064+00:00 | 85 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe can use dp to find at most 2 different ranges and return the maximum sum of these ranges. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nwe limit ourself to 2 picks .\nwe use the principal of take / not take at ... | 1 | 0 | ['Binary Search', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximize-win-from-two-segments | Javascript - DP + Sliding Window | javascript-dp-sliding-window-by-faustale-rizi | Code\n\n/**\n * @param {number[]} prizePositions\n * @param {number} k\n * @return {number}\n */\nvar maximizeWin = function (prizePositions, k) {\n const n = | faustaleonardo | NORMAL | 2023-02-07T01:02:29.310930+00:00 | 2023-02-07T01:02:29.310961+00:00 | 51 | false | # Code\n```\n/**\n * @param {number[]} prizePositions\n * @param {number} k\n * @return {number}\n */\nvar maximizeWin = function (prizePositions, k) {\n const n = prizePositions.length;\n const dp = new Array(n + 1).fill(0);\n let ans = 0;\n let start = 0;\n\n for (let end = 0; end < prizePositions.length; end++)... | 1 | 0 | ['JavaScript'] | 0 |
maximize-win-from-two-segments | [C++] Binary Search | DP | Beats 100% | Easy + Intuitive Explanation | Illustration | c-binary-search-dp-beats-100-easy-intuit-eryp | \n# Solution\nWe Calculate the maximum number of prizes we can collect if we start collecting from index i , using binary search to find the first index that ca | braindroid | NORMAL | 2023-02-04T23:03:18.229423+00:00 | 2023-02-04T23:03:18.229468+00:00 | 187 | false | \n# Solution\n**We Calculate the maximum number of prizes we can collect if we start collecting from index i , using binary search to find the first index that cannot be included if we start at index i.**\n\nAfter that we can just iterate over all index\'s **finding the maximum possible length of segment 1 , which was ... | 1 | 0 | ['Array', 'Binary Search', 'Dynamic Programming', 'C++'] | 2 |
maximize-win-from-two-segments | very easy and intuitive|| fully explained | very-easy-and-intuitive-fully-explained-ed65k | Intuition\n Describe your first thoughts on how to solve this problem. \nsee my first intuition was that , in none of the cases it is ideal for me to take two o | sippu | NORMAL | 2023-02-04T19:45:02.286196+00:00 | 2023-02-04T19:45:02.286238+00:00 | 158 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsee my first intuition was that , in none of the cases it is ideal for me to take two overlapping subarrays , if it is possible for me to take two non overlapping subarrays than that would always be better.\nThere is just one case where y... | 1 | 0 | ['Dynamic Programming', 'Sliding Window', 'C++'] | 0 |
maximize-win-from-two-segments | dp || sliding window || o(n) || leftmax + rightmax || faster 100% | dp-sliding-window-on-leftmax-rightmax-fa-z1da | Intuition\n For every index i, if we can get leftmax[i-1] and rightmax[i], we can iterate through i and get the max result.\n\nleftmax[i]: max on the left of | sagar-1209 | NORMAL | 2023-02-04T18:08:12.527938+00:00 | 2023-02-04T18:08:12.528016+00:00 | 96 | false | # Intuition\n For every index i, if we can get leftmax[i-1] and rightmax[i], we can iterate through i and get the max result.\n\nleftmax[i]: max on the left of index i (including i)\nrightmax[i]: max on the right of index i (including i)\n\nTo get leftmax[i]: the max between leftmax[i-1], and the number in the window... | 1 | 0 | ['Sliding Window', 'C++'] | 0 |
maximize-win-from-two-segments | [Java] DP + sliding window solution | java-dp-sliding-window-solution-by-opraj-begp | Intuition\nThe intuition behind solving the problem is to use dynamic programming to efficiently keep track of the maximum number of prizes that can be won at e | oprajapath | NORMAL | 2023-02-04T17:56:46.642098+00:00 | 2023-02-04T17:56:46.642148+00:00 | 542 | false | # Intuition\nThe intuition behind solving the problem is to use dynamic programming to efficiently keep track of the maximum number of prizes that can be won at each position.\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nStarting from the first position, the code uses a 2-dimens... | 1 | 0 | ['Java'] | 1 |
maximize-win-from-two-segments | C++ SOLUTION WITH UPPER_BOUND + SUFFIX MAXIMUM ARRAY | c-solution-with-upper_bound-suffix-maxim-n9wk | Time Complexity: O(nlog(n))\n\n\nclass Solution \n{\npublic:\n int maximizeWin(vector<int>& a, int k) \n {\n int n = a.size();\n vector<pair | theILICH | NORMAL | 2023-02-04T16:36:45.058032+00:00 | 2023-02-04T16:36:45.058076+00:00 | 894 | false | # Time Complexity: $$O(nlog(n))$$\n\n```\nclass Solution \n{\npublic:\n int maximizeWin(vector<int>& a, int k) \n {\n int n = a.size();\n vector<pair<int, int>> b(n), s(n);\n for (int i = 0; i < n; ++i)\n {\n int target = a[i] + k;\n int idx = max(0, (int)(upper_b... | 1 | 0 | ['C++'] | 1 |
maximize-win-from-two-segments | Slide Window | slide-window-by-linda2024-65e8 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2025-04-10T17:40:29.581246+00:00 | 2025-04-10T17:40:29.581246+00:00 | 2 | 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 |
maximize-win-from-two-segments | 6 lines scala recursion. three pointers, two sliding windows | 6-lines-scala-recursion-three-pointers-t-5wgq | scala []\nobject Solution {\n def maximizeWin(prizePositions: Array[Int], _k: Int): Int =\n def f(i:Int,j:Int,k:Int,mx0:Int, mx:Int): Int =\n if(k>= pr | vititov | NORMAL | 2024-12-08T19:20:33.413022+00:00 | 2024-12-08T19:20:33.413059+00:00 | 2 | false | ```scala []\nobject Solution {\n def maximizeWin(prizePositions: Array[Int], _k: Int): Int =\n def f(i:Int,j:Int,k:Int,mx0:Int, mx:Int): Int =\n if(k>= prizePositions.length) mx \n else if(prizePositions(k)-prizePositions(j) <= _k) f(i,j,k+1,mx0,mx max (k-j+1 + mx0))\n else if(prizePositions(j)-prize... | 0 | 0 | ['Scala'] | 0 |
maximize-win-from-two-segments | [Python] O(N*LogN) DP with binary search | python-onlogn-dp-with-binary-search-by-u-fo5i | Eg, k = 2\n\nSuppose we decide to pick current index, lets say item 1. Then we can pick all in range of 1 to 3 inclusive. So we simply binary search to find ind | user2292H | NORMAL | 2024-12-08T18:50:55.290230+00:00 | 2024-12-08T18:50:55.290256+00:00 | 2 | false | Eg, k = 2\n\nSuppose we decide to pick current index, lets say item 1. Then we can pick all in range of 1 to 3 inclusive. So we simply binary search to find index that is strictly greater than 3 in `prizePositions`. This allows to remove the need to keep track of chosen values and reduce time complexity.\n\nWe can also... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Binary Tree', 'Python'] | 0 |
maximize-win-from-two-segments | || ✅✅🙏Easiest Solution && Sliding Window Approach🙏✅✅ || | easiest-solution-sliding-window-approach-gd94 | Thanks for Upvote in Advance\u2B06\uFE0F\uD83D\uDE0A\uD83D\uDC95\n\n\n\n# Code\ncpp []\nclass Solution {\npublic:\n int maximizeWin(vector<int>& p, int k) {\ | Coding_With_Star | NORMAL | 2024-12-08T07:17:14.754814+00:00 | 2024-12-08T07:17:14.754863+00:00 | 13 | false | # Thanks for Upvote in Advance\u2B06\uFE0F\uD83D\uDE0A\uD83D\uDC95\n\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int maximizeWin(vector<int>& p, int k) {\n int n = p.size(), ans = 0, s = 0... | 0 | 1 | ['Array', 'Binary Search', 'Sliding Window', 'C++'] | 0 |
maximize-win-from-two-segments | O(N) Sliding window + DP solution | on-sliding-window-dp-solution-by-pipilon-ld8o | 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(n)\n# Code | pipilongstocking | NORMAL | 2024-12-08T07:08:05.506533+00:00 | 2024-12-08T07:09:31.647080+00:00 | 20 | false | # 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(n)$$\n# Code\n```python3 []\nclass Solution:\n def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n n = len(prizePos... | 0 | 0 | ['Dynamic Programming', 'Sliding Window', 'Python3'] | 0 |
maximize-win-from-two-segments | Binary Search + DP | binary-search-dp-by-pipilongstocking-wd5i | 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 | pipilongstocking | NORMAL | 2024-12-08T07:04:49.200601+00:00 | 2024-12-08T07:04:49.200634+00:00 | 15 | 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$$O(nlogn)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g.... | 0 | 0 | ['Binary Search', 'Dynamic Programming', 'Python3'] | 0 |
maximize-win-from-two-segments | Easy Solution | easy-solution-by-sunnapu_harshita-3yzs | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to choose two intervals of length k from a sorted list of prize pos | Sunnapu_Harshita | NORMAL | 2024-12-07T18:08:40.648978+00:00 | 2024-12-07T18:08:40.649017+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to choose two intervals of length k from a sorted list of prize positions to maximize the number of prizes we can collect. These intervals can overlap, but we want to find the optimal combination.\n\n# Approach\n<!-- D... | 0 | 0 | ['Java'] | 0 |
maximize-win-from-two-segments | Maximum Win From Two Segments | maximum-win-from-two-segments-by-naeem_a-0g9j | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nAssume dp[j] is the max segment length from (0, i).\ndp[j] = max(dp[j - 1 | Naeem_ABD | NORMAL | 2024-12-06T06:04:37.885656+00:00 | 2024-12-06T06:04:37.885693+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nAssume dp[j] is the max segment length from (0, i).\ndp[j] = max(dp[j - 1], valid(i, j)).\nFor (1,2,3,4) k = 4. If we add a new element 5.\n(1,2,3,4,5)\ndp[4] = range(0, 5) since (5 - 1 <= k) valid range(0, 4).\nIf the new a... | 0 | 0 | ['Java'] | 0 |
maximize-win-from-two-segments | Intuitive python solution -- Beats 100% | intuitive-python-solution-beats-100-by-d-ai2z | Intuition\n Describe your first thoughts on how to solve this problem. \nwe need to:\n- calulate valid segment lengths\n- Find two (non-ovelapping) segments tha | dimoka | NORMAL | 2024-12-04T00:50:32.879218+00:00 | 2024-12-04T00:50:32.879252+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe need to:\n- calulate valid segment lengths\n- Find two (non-ovelapping) segments that maximizes the coverage. For each segment, we look back and see what is the longest segment before and add that to the current segment length as a pot... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | C++ | Sliding Window + Dynamic Programming | c-sliding-window-dynamic-programming-by-htsb6 | 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 | Sriram8a | NORMAL | 2024-11-22T15:59:24.932224+00:00 | 2024-11-22T15:59:24.932282+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:\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 | ['Dynamic Programming', 'Sliding Window', 'C++'] | 0 |
maximize-win-from-two-segments | Calcualte all right segment win of every position (C++, O(n)) | calcualte-all-right-segment-win-of-every-gkk6 | Intuition\nit must be a O(n) complexity\n\n# Approach\nfirstly find out all the max win in the right side of index i (choose a segment in right),\n\nand then it | cx3129 | NORMAL | 2024-07-14T01:53:46.984845+00:00 | 2024-07-14T01:53:46.984876+00:00 | 4 | false | # Intuition\nit must be a O(n) complexity\n\n# Approach\nfirstly find out all the max win in the right side of index i (choose a segment in right),\n\nand then iterate all left segment, find out the max of total win (left side + right side which already calculated as above)\n\n# Complexity\n- Time complexity:\nO(n)\n\n... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Java O(n) slide window with dp | java-on-slide-window-with-dp-by-qingqian-is97 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nAssume dp[j] is the max | qingqianq | NORMAL | 2024-06-27T20:48:11.123725+00:00 | 2024-06-27T20:48:11.123744+00:00 | 14 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAssume dp[j] is the max segment length from (0, i).\ndp[j] = max(dp[j - 1], valid(i, j)).\nFor (1,2,3,4) k = 4. If we add a new element 5.\n(1,2,3,4,5)\ndp[4] = range(... | 0 | 0 | ['Java'] | 0 |
maximize-win-from-two-segments | Python || O(2N) || Easy Understanding || Left and Right Scan | python-o2n-easy-understanding-left-and-r-2f7m | Intuition\n Describe your first thoughts on how to solve this problem. \nWe create two lists to track the max number for one segment from both left and right si | liuyunjiahang | NORMAL | 2024-06-26T07:41:58.940096+00:00 | 2024-06-26T07:41:58.940118+00:00 | 42 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe create two lists to track the max number for one segment from both left and right sides, and there are at least one value.\n```\nleft = [1] * len(p)\nright = [1] * len(p)\n```\nThen max number for two segmens on `ith` element will equa... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | O(N) Forward/Backward Scan in Python3, Beating 100% | on-forwardbackward-scan-in-python3-beati-suy7 | Approach\nThis problem is about to find a pivot $p$ to split nums into two parts with the maximum value of $(l_2 - l_1 + 1) + (r_2 - r_1 + 1)$ for $l_1 \leq l_2 | metaphysicalist | NORMAL | 2024-05-22T17:01:15.757050+00:00 | 2024-05-22T17:03:38.043081+00:00 | 22 | false | # Approach\nThis problem is about to find a pivot $p$ to split `nums` into two parts with the maximum value of $(l_2 - l_1 + 1) + (r_2 - r_1 + 1)$ for $l_1 \\leq l_2 \\leq p \\leq r_1 \\leq r_2$ and $\\mathrm{nums}[l_2] - \\mathrm{nums}[l_1] \\leq k, \\mathrm{nums}[r_2] - \\mathrm{nums}[r_1] \\leq k$. \nTo speed up, we... | 0 | 0 | ['Two Pointers', 'Sliding Window', 'Python3'] | 0 |
maximize-win-from-two-segments | C++ Easy Solution | c-easy-solution-by-md_aziz_ali-rc3v | Code\n\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int n = prizePositions.size();\n vector<int> pre(n, | Md_Aziz_Ali | NORMAL | 2024-02-05T07:54:53.316077+00:00 | 2024-02-05T07:54:53.316109+00:00 | 17 | false | # Code\n```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int n = prizePositions.size();\n vector<int> pre(n, 0);\n\n int j = 0;\n int end = prizePositions[0] + k;\n int count = 0;\n int maxi = 0;\n\n for (int i = 0; i < n; i++) ... | 0 | 0 | ['Sliding Window', 'C++'] | 0 |
maximize-win-from-two-segments | The Only DP Solution || Sliding Window | the-only-dp-solution-sliding-window-by-v-ily1 | 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 | Verma_03 | NORMAL | 2024-01-13T12:55:45.688069+00:00 | 2024-01-13T12:55:45.688088+00:00 | 11 | 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 |
maximize-win-from-two-segments | rust: simple partition_point and max array, beats 100% | rust-simple-partition_point-and-max-arra-mra4 | \n# Code\n\nimpl Solution {\n pub fn maximize_win(prize_positions: Vec<i32>, k: i32) -> i32 {\n let mut i = 0;\n let mut cmax = vec![0; prize_p | happysings | NORMAL | 2024-01-07T09:01:38.240968+00:00 | 2024-01-07T09:01:38.241005+00:00 | 3 | false | \n# Code\n```\nimpl Solution {\n pub fn maximize_win(prize_positions: Vec<i32>, k: i32) -> i32 {\n let mut i = 0;\n let mut cmax = vec![0; prize_positions.len() + 1];\n let mut max = 0; // result\n while i < prize_positions.len() {\n let curr = prize_positions[i];\n ... | 0 | 0 | ['Rust'] | 0 |
maximize-win-from-two-segments | Simple DP 🚀 || C++ || TC: O(N*3) | simple-dp-c-tc-on3-by-_maityamit-0rjc | \nint const N = 1e5;\nclass Solution {\npublic:\n int dp[N+1][3];\n int helper(int idx,int k,vector<int> &pp,int kk){\n if(idx==pp.size()||k==0) re | _maityamit | NORMAL | 2024-01-06T09:26:35.459514+00:00 | 2024-01-06T09:26:35.459550+00:00 | 8 | false | ```\nint const N = 1e5;\nclass Solution {\npublic:\n int dp[N+1][3];\n int helper(int idx,int k,vector<int> &pp,int kk){\n if(idx==pp.size()||k==0) return 0;\n if(dp[idx][k]!=-1) return dp[idx][k];\n int ntk = helper(idx+1,k,pp,kk);\n int index = lower_bound(pp.begin(),pp.end(),pp[idx]... | 0 | 0 | ['Dynamic Programming', 'C', 'C++'] | 0 |
maximize-win-from-two-segments | Recursive || 2D dp | recursive-2d-dp-by-sh1n0b1-ne35 | When skipping, we skip all the occurances of current element.\nWhen picking, we pick till the indx where the element is greater than current element + k.\n\n# C | sh1n0b1 | NORMAL | 2024-01-03T18:00:48.935661+00:00 | 2024-01-03T18:00:48.935698+00:00 | 12 | false | When skipping, we skip all the occurances of current element.\nWhen picking, we pick till the indx where the element is greater than current element + k.\n\n# Code\n```\nclass Solution {\npublic:\n int solve(vector<int>& prizePositions, vector<vector<int>>& dp, int k, int indx, int segments) {\n if(indx == pr... | 0 | 0 | ['Recursion', 'C++'] | 0 |
maximize-win-from-two-segments | [C] sliding window, suffixMax, two ptrs | Time: O(n), Space: O(n) | c-sliding-window-suffixmax-two-ptrs-time-zr5n | C []\nint maximizeWin(\n\tconst int * const posArr,\n\tconst int posArrLen,\n\n\tconst int len\n){\n\tassert(posArrLen >= 1 && len >= 0);\n\n\tstruct {\n\t\tint | zhang_jiabo | NORMAL | 2023-11-25T12:50:21.858404+00:00 | 2023-11-25T12:50:21.858433+00:00 | 4 | false | ```C []\nint maximizeWin(\n\tconst int * const posArr,\n\tconst int posArrLen,\n\n\tconst int len\n){\n\tassert(posArrLen >= 1 && len >= 0);\n\n\tstruct {\n\t\tint start;\n\t\tint cnt;\n\t} intervalArr[posArrLen];\n\tint intervalArrLen = 0;\n\tfor (int left = 0, right = 0; left < posArrLen; ){\n\t\twhile (right < posAr... | 0 | 0 | ['C'] | 0 |
maximize-win-from-two-segments | Linear time using monotonic queue + sliding window | linear-time-using-monotonic-queue-slidin-39zw | Intuition\nMight as well be greedy with placement of two intervals and make them disjoint. Why make them overlapping and risk missing out on some prizes?\n\n# A | c-m-d- | NORMAL | 2023-11-17T00:52:50.915985+00:00 | 2023-11-17T00:52:50.916006+00:00 | 4 | false | # Intuition\nMight as well be greedy with placement of two intervals and make them disjoint. Why make them overlapping and risk missing out on some prizes?\n\n# Approach\nThought about binary search but realized we can solve it in linear time with a sliding window approach and monotonic queue. Straightforward sliding w... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Rust Solution using Sliidng Window and DP | rust-solution-using-sliidng-window-and-d-dv8x | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nimpl Solution {\n pub fn maximize_win(prize_positions: Vec<i32>, k: i32) -> i32 | rchaser53 | NORMAL | 2023-11-04T08:09:35.841732+00:00 | 2023-11-04T08:09:35.841751+00:00 | 9 | false | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nimpl Solution {\n pub fn maximize_win(prize_positions: Vec<i32>, k: i32) -> i32 {\n let n = prize_positions.len();\n if n == 1 {\n return 1\n }\n\n let mut memo = vec![0;n];\n let mut max = 0;\n let mut r... | 0 | 0 | ['Dynamic Programming', 'Sliding Window', 'Rust'] | 0 |
maximize-win-from-two-segments | maximize win from two segments | maximize-win-from-two-segments-by-2020ku-cd3b | 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 | 2020kucp1032 | NORMAL | 2023-10-27T03:46:51.844610+00:00 | 2023-10-27T03:46:51.844642+00:00 | 33 | 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 | 1 | ['Python3'] | 0 |
maximize-win-from-two-segments | C++ Implementation using Binary Search + Brute Force | c-implementation-using-binary-search-bru-tzin | Key Points\n- Find the unique segment till the length k using Binary Search\n- Then sort these segments according to the highest length\n- Then Brute Force by P | ayushnautiyal1110 | NORMAL | 2023-10-24T18:38:15.301814+00:00 | 2023-10-24T18:38:15.301831+00:00 | 14 | false | **Key Points**\n- Find the unique segment till the length k using Binary Search\n- Then sort these segments according to the highest length\n- Then Brute Force by Picking one of the greatest no till 100 times and matching with the other greatest no\n\n# Code\n```\nclass Solution {\npublic:\n static bool cmp(pair<int... | 0 | 0 | ['Binary Search', 'C++'] | 0 |
maximize-win-from-two-segments | Golang sliding solution | golang-sliding-solution-by-tjucoder-zcba | Code\ngo\nfunc maximizeWin(prizePositions []int, k int) int {\n\thash := make(map[int]int)\n\tfor _, p := range prizePositions {\n\t\thash[p]++\n\t}\n\tkeys := | tjucoder | NORMAL | 2023-09-14T16:52:22.264517+00:00 | 2023-09-14T16:52:22.264541+00:00 | 10 | false | # Code\n```go\nfunc maximizeWin(prizePositions []int, k int) int {\n\thash := make(map[int]int)\n\tfor _, p := range prizePositions {\n\t\thash[p]++\n\t}\n\tkeys := make([]int, 0, len(hash))\n\tfor k := range hash {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Ints(keys)\n\tl1, r1 := 0, 0\n\tmaxWinScore := hash[keys[0]]\n\... | 0 | 0 | ['Sliding Window', 'Go'] | 0 |
maximize-win-from-two-segments | Python Sliding Window O(N). Clean Code + Intuition + Similar problem | python-sliding-window-on-clean-code-intu-la19 | Intuition\nThis is the same problem as:\nhttps://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/editorial, Approach 1: Bidirectional Dynamic Programm | bwindsor22 | NORMAL | 2023-08-20T18:05:38.242036+00:00 | 2023-08-20T18:23:35.897638+00:00 | 43 | false | # Intuition\nThis is the same problem as:\nhttps://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/editorial, Approach 1: Bidirectional Dynamic Programming, where you want a max to the left of i and a max to the right of i.\n\n# Approach\n1. Use a counter to get a num -> count mapping so the distance to itera... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | Swift, DP + Sliding Segment, O(n) | swift-dp-sliding-segment-on-by-sergeyles-3ey6 | Intuition\nThe problem of maximizing wins from one segment, can be effectively solved using a sliding window approach. By utilizing this approach, we can calcul | sergeyleschev | NORMAL | 2023-08-19T15:40:41.002907+00:00 | 2023-08-19T15:41:21.073763+00:00 | 1 | false | # Intuition\nThe problem of maximizing wins from one segment, can be effectively solved using a sliding window approach. By utilizing this approach, we can calculate the outcome by considering the dynamic programming (dp) values.\n\n# Approach\nTo solve this problem, we establish a sliding segment, resembling a sliding... | 0 | 0 | ['Swift'] | 0 |
maximize-win-from-two-segments | python O(N) runtime O(1) space | python-on-runtime-o1-space-by-sroninio-za2q | Approach\nIterate with head right to left.\nAt any iteration maintain the following:\n- longest segment that ends exactly at head on the right side of the segme | sroninio | NORMAL | 2023-08-08T08:19:08.985433+00:00 | 2023-08-08T08:19:08.985451+00:00 | 17 | false | # Approach\n$$Iterate$$ with $$head$$ right to left.\nAt any iteration maintain the following:\n- longest segment that ends exactly at $$head$$ on the right side of the segment: $$currLeft$$ stands for the number of prizes in this segment and $$leftEdge$$ stands for the left edge of the segment\n- longest segment that ... | 0 | 0 | ['Python'] | 0 |
maximize-win-from-two-segments | Ruby O(N) | ruby-on-by-fnkwjgsm3qruaf-7lod | \nruby\n# @param {Integer[]} prize_positions\n# @param {Integer} k\n# @return {Integer}\ndef maximize_win(prize_positions, k)\n # dp[idx] := max prize if one o | FNkWJgsm3QruaF | NORMAL | 2023-08-05T21:53:00.507839+00:00 | 2023-08-05T21:53:00.507860+00:00 | 1 | false | \n```ruby\n# @param {Integer[]} prize_positions\n# @param {Integer} k\n# @return {Integer}\ndef maximize_win(prize_positions, k)\n # dp[idx] := max prize if one optimal segment is chosen among the first k prizes\n dp = Array.new(prize_positions.length + 1, 0)\n res, left = 0, 0\n for right in 0...prize_positions.le... | 0 | 0 | ['Ruby'] | 0 |
maximize-win-from-two-segments | fully explained c++ solution | fully-explained-c-solution-by-deviltrek-znuv | 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 | deviltrek | NORMAL | 2023-07-20T15:41:49.721479+00:00 | 2023-07-20T15:41:49.721509+00:00 | 13 | 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 |
maximize-win-from-two-segments | Python3 Dynamic programming | python3-dynamic-programming-by-wxli3388-ok5f | Approach\n- Need to choose at most two segment, the dfs function should go through all index or run out of two segments.\n- There are two states in each index, | wxli3388 | NORMAL | 2023-07-16T15:31:29.437668+00:00 | 2023-07-16T16:00:40.265955+00:00 | 18 | false | # Approach\n- Need to choose at most two segment, the dfs function should go through all index or run out of two segments.\n- There are two states in each index, pick or not pick\n- If pick the idx, skip the value less or equal than the value plus k. \n ex: `prize[idx] = 1 and k = 2`\n It can cover from value 1 t... | 0 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
maximize-win-from-two-segments | DP. Time: O(3*n), Space: O(2*n) | dp-time-o3n-space-o2n-by-iitjsagar-e5lj | class Solution(object):\n def maximizeWin(self, prizePositions, k):\n """\n :type prizePositions: List[int]\n :type k: int\n :rty | iitjsagar | NORMAL | 2023-07-15T20:51:36.734321+00:00 | 2023-07-15T20:51:36.734348+00:00 | 2 | false | class Solution(object):\n def maximizeWin(self, prizePositions, k):\n """\n :type prizePositions: List[int]\n :type k: int\n :rtype: int\n """\n \n n = len(prizePositions)\n \n jump_arr = [0 for i in range(n)]\n r = n-1\n \n for i in... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | Best DP + Binary search solution(c++ solution) | best-dp-binary-search-solutionc-solution-biio | 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 | jishudip389 | NORMAL | 2023-07-15T20:11:28.353486+00:00 | 2023-07-15T20:11:28.353510+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:\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 |
maximize-win-from-two-segments | Simple 1D dp C++ | simple-1d-dp-c-by-user0592e-vqd8 | \n\nVariables:\n\nn represents the size of the input array nums.\nstart keeps track of the starting index of the segment.\nans stores the maximum number of priz | user0592E | NORMAL | 2023-07-04T09:12:10.940755+00:00 | 2023-07-04T09:12:10.940783+00:00 | 24 | false | \n\nVariables:\n\nn represents the size of the input array nums.\nstart keeps track of the starting index of the segment.\nans stores the maximum number of prizes won.\ndp is an auxiliary array that keeps track of the maximum number of prizes that can be won up to the current index.\n\n\nIterate through the elements of... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | 2p+dp ^^ | 2pdp-by-andrii_khlevniuk-63jl | time: O(N); space: O(N)\n\nint maximizeWin(vector<int>& x, int k) \n{\n\tint out{}; \n\tfor(int i{}, j{}, d[100002]{}; i<size(x); )\n\t\tif(x[i]-x[j]<=k)\n\t\t\ | andrii_khlevniuk | NORMAL | 2023-07-03T12:26:35.201906+00:00 | 2023-07-03T15:22:45.930874+00:00 | 13 | false | **time: `O(N)`; space: `O(N)`**\n```\nint maximizeWin(vector<int>& x, int k) \n{\n\tint out{}; \n\tfor(int i{}, j{}, d[100002]{}; i<size(x); )\n\t\tif(x[i]-x[j]<=k)\n\t\t\t++i,\n\t\t\td[i] = max(d[i-1], i-j),\n out = max(out, i-j+d[j]);\n\t\telse\n\t\t\t++j;\n\treturn out; \n}\n``` | 0 | 0 | ['C', 'C++'] | 0 |
maximize-win-from-two-segments | O(N) approach using dynamic programming and sliding window | on-approach-using-dynamic-programming-an-2usj | Approach\nDynamic Programming with Sliding Window\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution(object):\n | the_first_avenger_2023 | NORMAL | 2023-06-02T09:27:41.362149+00:00 | 2023-06-02T09:29:07.824076+00:00 | 33 | false | # Approach\nDynamic Programming with Sliding Window\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution(object):\n def maximizeWin(self, P, k):\n #Have a dp array to record the max length of the first segment at i:\n dp = [0] * len(P)\n res... | 0 | 0 | ['Python'] | 0 |
maximize-win-from-two-segments | Store longest range in left and right using sliding window | store-longest-range-in-left-and-right-us-113v | \nclass Solution:\n def maximizeWin(self, pos, k):\n n = len(pos)\n l = [0] * n\n r = [0] * n\n i = 0\n for j in range(n): | theabbie | NORMAL | 2023-05-12T01:23:07.829380+00:00 | 2023-05-12T01:23:07.829422+00:00 | 21 | false | ```\nclass Solution:\n def maximizeWin(self, pos, k):\n n = len(pos)\n l = [0] * n\n r = [0] * n\n i = 0\n for j in range(n):\n while i < j and pos[j] - pos[i] > k:\n i += 1\n if pos[j] - pos[i] <= k:\n l[j] = j - i + 1\n i... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | C++||DP||Sliding window approaches🔥🚀🔥✨💖 | cdpsliding-window-approaches-by-curious_-4gp2 | Code\n\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int res =0;;\n int n = prizePositions.size();\n | Curious_hritik | NORMAL | 2023-04-09T09:23:51.139225+00:00 | 2023-04-09T09:23:51.139271+00:00 | 42 | false | # Code\n```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int res =0;;\n int n = prizePositions.size();\n int j=0;\n\n vector<int>dp(n+1,0);\n for(int i=0;i<n;i++){\n while(prizePositions[j]<prizePositions[i]-k)\n j++... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Use two points cleverly | use-two-points-cleverly-by-fredrick_li-n2y2 | 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 | Fredrick_LI | NORMAL | 2023-03-10T21:04:47.478566+00:00 | 2023-03-10T21:04:47.478618+00:00 | 87 | 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 |
maximize-win-from-two-segments | Python (Simple DP + Sliding Window) | python-simple-dp-sliding-window-by-rnota-68qj | 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 | rnotappl | NORMAL | 2023-03-03T16:16:02.938882+00:00 | 2023-03-03T16:16:02.938912+00:00 | 79 | 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 |
maximize-win-from-two-segments | [1Sentence] Slide a window saving best solution so far, return max(sum(window) + best to the left) | 1sentence-slide-a-window-saving-best-sol-0l1c | Upvote if you like the simplicity\n\n\ndef maximizeWin(self, prizes: List[int], k: int) -> int:\n bestBefore = [0] * (len(prizes) + 1)\n bestBeforeSoFar = | Balwierz | NORMAL | 2023-02-18T13:45:31.484905+00:00 | 2023-02-18T13:45:31.484938+00:00 | 63 | false | # Upvote if you like the simplicity\n\n```\ndef maximizeWin(self, prizes: List[int], k: int) -> int:\n bestBefore = [0] * (len(prizes) + 1)\n bestBeforeSoFar = 0\n ret = 0\n runSum = 0\n i, j = 0, 0\n while j<len(prizes):\n x = prizes[j]\n while j<len(prizes) and prizes[j] == x:\n ... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | Python DP | python-dp-by-dinar-q4g2 | \nclass Solution:\n def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n\n prefix = [0] * len(prizePositions)\n sufix = [0] * len | dinar | NORMAL | 2023-02-18T11:46:33.837388+00:00 | 2023-02-18T11:46:33.837434+00:00 | 30 | false | ```\nclass Solution:\n def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n\n prefix = [0] * len(prizePositions)\n sufix = [0] * len(prizePositions)\n prefix[0] = 1\n sufix[-1] = 1\n left, right = 0, 1\n while right < len(prizePositions):\n if prizeP... | 0 | 0 | ['Dynamic Programming', 'Python'] | 0 |
maximize-win-from-two-segments | Prefix+Suffix+BS using python | prefixsuffixbs-using-python-by-venkataak-k2tb | Code\n\nclass Solution:\n def maximizeWin(self, pp: List[int], k: int) -> int:\n n=len(pp)\n \n pre=[0]*(n)\n suff=[0]*(n)\n | venkataakhil4518 | NORMAL | 2023-02-18T10:11:45.997676+00:00 | 2023-02-18T10:11:45.997722+00:00 | 46 | false | # Code\n```\nclass Solution:\n def maximizeWin(self, pp: List[int], k: int) -> int:\n n=len(pp)\n \n pre=[0]*(n)\n suff=[0]*(n)\n \n for i in range(n-1,-1,-1):\n pos=bisect_right(pp,pp[i]+k)\n if i==n-1:\n suff[i]=pos-i\n else:... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | Python solution using DP | python-solution-using-dp-by-pradoshsahoo-3rgi | Code\n\nclass Solution:\n def maximizeWin(self, A: List[int], k: int) -> int:\n dp = [0] * (len(A) + 1)\n res = j = 0\n for i, a in enum | pradoshsahoo81 | NORMAL | 2023-02-18T06:29:37.553573+00:00 | 2023-02-18T06:29:37.553619+00:00 | 38 | false | # Code\n```\nclass Solution:\n def maximizeWin(self, A: List[int], k: int) -> int:\n dp = [0] * (len(A) + 1)\n res = j = 0\n for i, a in enumerate(A):\n while A[j] < A[i] - k: j += 1\n res = max(res, i - j + 1 + dp[j])\n dp[i + 1] = max(dp[i], i - j + 1)\n ... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | Swift | One-Liner | swift-one-liner-by-upvotethispls-ul1a | One-Liner, terse (accepted answer)\n\nclass Solution {\n func maximizeWin(_ p: [Int], _ k: Int) -> Int {\n p.indices.reduce(into:(0,0,[0])){while p[$0.0]<p | UpvoteThisPls | NORMAL | 2023-02-16T23:15:26.185660+00:00 | 2023-02-16T23:21:16.576116+00:00 | 21 | false | **One-Liner, terse (accepted answer)**\n```\nclass Solution {\n func maximizeWin(_ p: [Int], _ k: Int) -> Int {\n p.indices.reduce(into:(0,0,[0])){while p[$0.0]<p[$1]-k{$0.0+=1};let x=$1-$0.0+1;$0.1=max($0.1,x+$0.2[$0.0]);$0.2+=[max($0.2[$1],x)]}.1\n }\n}\n```\n\n---\n\n**One-Liner, expanded and annotated (accept... | 0 | 0 | ['Swift'] | 0 |
maximize-win-from-two-segments | Easy C++ O(N) solution || sliding segment | easy-c-on-solution-sliding-segment-by-sa-xjjc | \nclass Solution {\npublic:\n int maximizeWin(vector<int>& arr, int k) {\n //for every index store the result\n vector<int> dp(arr.size());\n | saiteja_balla0413 | NORMAL | 2023-02-14T10:29:11.680224+00:00 | 2023-02-14T10:29:11.680270+00:00 | 71 | false | ```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& arr, int k) {\n //for every index store the result\n vector<int> dp(arr.size());\n \n //dp[i] stores the max pos covered by any single segment of length k\n int res=0;\n int i=0;\n int maxiSingle=0;\n ... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | C++ Solution Queue | c-solution-queue-by-retire-xpr7 | Code\n\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) \n {\n int f[3];\n f[0]=f[1]=f[2]=0;\n queue< | Retire | NORMAL | 2023-02-13T15:40:35.572041+00:00 | 2023-02-13T15:40:35.572080+00:00 | 29 | false | # Code\n```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) \n {\n int f[3];\n f[0]=f[1]=f[2]=0;\n queue<int>q1;\n queue<pair<int,int>>q2;\n for(auto &x:prizePositions)\n {\n f[0]+=1;\n q1.push(x);\n while(... | 0 | 0 | ['Queue', 'C++'] | 0 |
maximize-win-from-two-segments | easy short efficient clean code | easy-short-efficient-clean-code-by-maver-rqvs | \nclass Solution {\npublic:\ntypedef long long ll;\n#define vi(x) vector<x>\nint maximizeWin(vector<int>&v, int k) {\n ll n=v.size(), ans=0;\n vi(ll)dp(n) | maverick09 | NORMAL | 2023-02-12T05:40:41.735876+00:00 | 2023-02-12T05:40:41.735915+00:00 | 38 | false | ```\nclass Solution {\npublic:\ntypedef long long ll;\n#define vi(x) vector<x>\nint maximizeWin(vector<int>&v, int k) {\n ll n=v.size(), ans=0;\n vi(ll)dp(n);\n for(ll i=0, j=0;i<n;++i){\n while(j<i && v[i]-v[j]>k){\n ++j;\n }\n dp[i]=max(i?dp[i-1]:0, i-j+1);\n ans=max(an... | 0 | 0 | ['Dynamic Programming', 'C', 'Sliding Window'] | 0 |
maximize-win-from-two-segments | [Python] Maximize Left and Right Segments, The Best | python-maximize-left-and-right-segments-53hqh | Intuition\nSplit the prizes list such that the number of maximum-count prizes segment of length k in left and right part of the split is maximized.\n\nThe Best! | Triquetra | NORMAL | 2023-02-11T19:38:20.243427+00:00 | 2023-02-11T19:38:20.243490+00:00 | 41 | false | # Intuition\nSplit the prizes list such that the number of maximum-count prizes segment of length $$k$$ in left and right part of the split is maximized.\n\nThe Best!\n\n# Approach\nUse a sliding window to build two aggregated maximums of $$k$$-length prizes counts when moving from left and from right.\n\nHandle a spec... | 0 | 0 | ['Python3'] | 0 |
maximize-win-from-two-segments | C++ || Binary Search || Lower bound || Suffix Max | c-binary-search-lower-bound-suffix-max-b-4zd9 | Complexity\n- Time complexity: O(NlogN+N+N)\n\n- Space complexity: O(3N)\n\n# Code\n\nclass Solution {\npublic:\n\n //find last value of val\n //1 2 2 3 | sangramsinh | NORMAL | 2023-02-11T04:41:05.834640+00:00 | 2023-02-11T04:41:05.834677+00:00 | 97 | false | # Complexity\n- Time complexity: O(NlogN+N+N)\n\n- Space complexity: O(3N)\n\n# Code\n```\nclass Solution {\npublic:\n\n //find last value of val\n //1 2 2 3 4 5\n //2 3 3 4 5 5\n int lowerBound(vector<int>& nums, int &ws,int &n, int lo , int hi, int val){\n int j = -1;\n while(lo<=hi){\n ... | 0 | 0 | ['Binary Search', 'C++'] | 0 |
maximize-win-from-two-segments | My Solution | my-solution-by-hope_ma-treu | \n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `prizePositions`\n */\nclass Solution {\n public:\n int ma | hope_ma | NORMAL | 2023-02-10T12:57:15.170446+00:00 | 2023-02-10T12:57:15.170482+00:00 | 5 | false | ```\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `prizePositions`\n */\nclass Solution {\n public:\n int maximizeWin(const vector<int> &prizePositions, const int k) {\n const int n = static_cast<int>(prizePositions.size());\n int left[n];\n for (int max_p... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | [Java Solution Using Segment Tree ] | java-solution-using-segment-tree-by-gane-tmu2 | Consider array arr[1,1,2,2,3,3,5] and k=2 and make an array grtrOrEq which stores at index i , index of least element greater than arr[i]+k . For example grtrOr | Ganesha_ | NORMAL | 2023-02-10T09:17:07.912124+00:00 | 2023-02-10T09:17:07.912153+00:00 | 69 | false | Consider array arr[1,1,2,2,3,3,5] and k=2 and make an array grtrOrEq which stores at index i , index of least element greater than arr[i]+k . For example grtrOrEq will look like [6, 6, 6, 6, 7, 7, 7]. Now make an array ans where at any index i ans[i]=grtrOrEq[i]-i.\nCode for grtrOrEq array\n```\nfor(int i=0;i<grtrOrEq.... | 0 | 0 | ['Tree', 'Binary Tree', 'Java'] | 1 |
maximize-win-from-two-segments | Easy c++ solution 100% faster in binarySearch+dp | easy-c-solution-100-faster-in-binarysear-3cky | Intuition\n Describe your first thoughts on how to solve this problem. \nif use the the array then you find that it is sorted so we can apply binary search over | Balram_54321 | NORMAL | 2023-02-08T15:16:23.636117+00:00 | 2023-02-08T15:17:37.557980+00:00 | 15 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nif use the the array then you find that it is sorted so we can apply binary search over here\n# Approach\n<!-- Describe your approach to solving the problem. -->\nbinary search and dynamic programing\n# Complexity\n- Time complexity:\n<!-... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | C++ | Dp | Binary Search | Sliding Window | c-dp-binary-search-sliding-window-by-ari-g506 | i) First create all ranges i.e take all values as starting points and again all of them as ending points using sliding window. Store all these ranges and their | arindombora_ug | NORMAL | 2023-02-08T09:02:03.172071+00:00 | 2023-02-08T09:02:03.172124+00:00 | 67 | false | i) First create all ranges i.e take all values as starting points and again all of them as ending points using sliding window. Store all these ranges and their sums.\nii) Sort the values according to starting index and apply dp to choose 2 non-overlapping intervals with maximum sum. Use Binary search to avoid overlappi... | 0 | 0 | ['Dynamic Programming', 'C', 'Sliding Window', 'Binary Tree'] | 0 |
maximize-win-from-two-segments | C++ Easy solution BS | c-easy-solution-bs-by-fagun06-s3nf | \n# Code\n\nclass Solution {\npublic:\n int n;\n int bns(int x,vector<int>&v) {\n int l=0,r=n-1;\n int res;\n while(l<=r) {\n | Fagun06 | NORMAL | 2023-02-08T05:22:05.436406+00:00 | 2023-02-08T05:22:05.436435+00:00 | 16 | false | \n# Code\n```\nclass Solution {\npublic:\n int n;\n int bns(int x,vector<int>&v) {\n int l=0,r=n-1;\n int res;\n while(l<=r) {\n int md=(l+r)/2;\n if(v[md]<=x) res=md,l=md+1;\n else r=md-1;\n }\n return res;\n }\n int maximizeWin(vector<int... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Worst Implementation of Binary Search | worst-implementation-of-binary-search-by-23pe | \nclass Solution {\n public int maximizeWin(int[] arr, int k) {\n int n = arr.length;\n int[] pre = new int[n];\n int count = 0;\n | MaawanAhmad | NORMAL | 2023-02-07T19:25:47.777623+00:00 | 2023-02-07T19:25:47.777667+00:00 | 20 | false | ```\nclass Solution {\n public int maximizeWin(int[] arr, int k) {\n int n = arr.length;\n int[] pre = new int[n];\n int count = 0;\n for(int i = 0 ; i < arr.length ; i++){\n pre[i] = count;\n count++;\n }\n for(int i = arr.length - 1 ; i >= 0 ; i--){\n... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | C++ || easy solution || DP + Sliding Window || beats 88% | c-easy-solution-dp-sliding-window-beats-5rzjp | \n# Code\n\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int n = prizePositions.size(), start = 0, ans = 0;\n | Madhur_Jain | NORMAL | 2023-02-07T18:31:54.617484+00:00 | 2023-02-07T18:32:45.921576+00:00 | 36 | false | \n# Code\n```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& prizePositions, int k) {\n int n = prizePositions.size(), start = 0, ans = 0;\n vector<int>dp(n);\n for(int end=0; end<n; end++) {\n while(prizePositions[end] - prizePositions[start] > k)\n start++;... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | C++ | c-by-tlu22-j9k0 | 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 | tlu22 | NORMAL | 2023-02-07T15:36:45.462968+00:00 | 2023-02-07T15:36:45.491918+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:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Sliding window O(N) | sliding-window-on-by-sandeep_003-aipq | \n\n# Code\n\nclass Solution {\npublic:\n int maximizeWin(vector<int>& v, int k) {\n int n=v.size(),ans=0;\n\n // sliding window from right\n | sandeep_003 | NORMAL | 2023-02-07T07:10:28.561952+00:00 | 2023-02-07T07:10:28.561995+00:00 | 67 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int maximizeWin(vector<int>& v, int k) {\n int n=v.size(),ans=0;\n\n // sliding window from right\n int cnt=0,j=n-1;\n vector<int> res(n+2,0);\n for(int i=n-1;i>=0;i--){\n cnt++;\n while(v[j]-v[i]>k){ \n j-... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Memoization -> Tabulation | DP + BS | C++ | memoization-tabulation-dp-bs-c-by-tushar-6y2o | Memoization\n\nclass Solution {\n int dfs(int i, int n, int k, int cnt, vector<int> &pp, vector<vector<int>> &dp) {\n if(i == n) return 0;\n if | TusharBhart | NORMAL | 2023-02-06T17:14:32.190708+00:00 | 2023-02-06T17:14:32.190755+00:00 | 69 | false | # Memoization\n```\nclass Solution {\n int dfs(int i, int n, int k, int cnt, vector<int> &pp, vector<vector<int>> &dp) {\n if(i == n) return 0;\n if(dp[i][cnt] != -1) return dp[i][cnt];\n\n int notPick = dfs(i + 1, n, k, cnt, pp, dp), pick = 0;\n if(cnt) {\n int pos = lower_bou... | 0 | 0 | ['Binary Search', 'Dynamic Programming', 'Memoization', 'C++'] | 0 |
maximize-win-from-two-segments | [Java] Prefix MAX + Binary Search, O(nlogn) solution | java-prefix-max-binary-search-onlogn-sol-qfk6 | \nclass Solution {\n public int maximizeWin(int[] a, int k) {\n int max_till_here=0;\n int maxans=0;\n for(int j=0;j<a.length;j++)\n | kritikmodi | NORMAL | 2023-02-06T13:46:53.068183+00:00 | 2023-03-28T10:05:45.745930+00:00 | 39 | false | ```\nclass Solution {\n public int maximizeWin(int[] a, int k) {\n int max_till_here=0;\n int maxans=0;\n for(int j=0;j<a.length;j++)\n {\n int end=j;\n int l=0;\n int r=a.length-1;\n while(l<=r)\n {\n int mid=l+(r-l)/2... | 0 | 0 | ['Binary Search', 'Sliding Window'] | 0 |
maximize-win-from-two-segments | Clean prefix solution || C++ | clean-prefix-solution-c-by-_pinocchio-511m | Approach\nCode size is huge but not logic is\n- Left array : At every index find no. of prizes in a window of k (idx to left)\n- Right array : At every index fi | _Pinocchio | NORMAL | 2023-02-06T09:07:11.702679+00:00 | 2023-02-06T16:34:21.870108+00:00 | 43 | false | # Approach\nCode size is huge but not logic is\n- Left array : At every index find no. of prizes in a window of k (idx to left)\n- Right array : At every index find no. of prizes in a window of k (idx to right)\n- prefix array : keep track of maximum no. of prize till this point from right\n- Last for loop : at every i... | 0 | 0 | ['C++'] | 0 |
maximize-win-from-two-segments | Detailed solution with comments | Sliding Window | Prefix Sum | Suffix Sum | O(N) | detailed-solution-with-comments-sliding-rpy4z | \nclass Solution\n{\n public:\n \t// basically for ant index i, (0,i) will give me one segment out of all segments possible\n \t//in this range ( | Dark_kryptonian23 | NORMAL | 2023-02-06T08:34:10.817082+00:00 | 2023-02-06T08:36:19.751321+00:00 | 36 | false | ```\nclass Solution\n{\n public:\n \t// basically for ant index i, (0,i) will give me one segment out of all segments possible\n \t//in this range (0,i) in such a way that it will give me max. prize. Similarly (i+1,n-1)\n \t// will give me one segment out of all segments possible in this range (i+1... | 0 | 0 | ['Prefix Sum'] | 0 |
maximize-win-from-two-segments | Problem with the Problem Description | problem-with-the-problem-description-by-ryj4k | Anybody else read this problem wrong to where they thought a segment must contain both the left and the right endpoints to be valid? What led me to think this i | throwaway1973 | NORMAL | 2023-02-06T00:47:55.925254+00:00 | 2023-02-06T00:52:55.221313+00:00 | 34 | false | Anybody else read this problem wrong to where they thought a segment must contain both the left and the right endpoints to be valid? What led me to think this is the fact it said the \'The length of each segment must be k\', which made me think that the right endpoint of the segment should always be contained within th... | 0 | 0 | [] | 0 |
maximize-win-from-two-segments | JavaScript (DP) | javascript-dp-by-swseverance-kirg | javascript\nvar maximizeWin = function(prizePositions, k) {\n const dp = {};\n \n for (const position of prizePositions)\n dp[position] = Array(3).fill(0) | swseverance | NORMAL | 2023-02-05T22:02:33.761193+00:00 | 2023-02-08T14:07:30.376792+00:00 | 59 | false | ```javascript\nvar maximizeWin = function(prizePositions, k) {\n const dp = {};\n \n for (const position of prizePositions)\n dp[position] = Array(3).fill(0);\n \n for (let i = 0, j = 0; i < prizePositions.length; ++i) {\n const position = prizePositions[i];\n \n // range of prizes we can collect is [p... | 0 | 0 | ['JavaScript'] | 0 |
maximum-value-of-k-coins-from-piles | [Java/C++/Python] Top-down DP solution | javacpython-top-down-dp-solution-by-lee2-qk4e | Intuition\nTop down dynamic programming.\nAlso noticed that some people already get accepted, a dp program.\n\n\n# Explanation\ndp[i,k] means picking k elements | lee215 | NORMAL | 2022-03-27T04:03:57.397740+00:00 | 2022-03-27T04:56:36.321129+00:00 | 22,547 | false | # **Intuition**\nTop down dynamic programming.\nAlso noticed that some people already get accepted, a dp program.\n<br>\n\n# **Explanation**\n`dp[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 o... | 183 | 3 | ['C', 'Python', 'Java'] | 32 |
maximum-value-of-k-coins-from-piles | Image Explanation🏆- [Top Down DP - Easy & Concise] - C++/Java/Python | image-explanation-top-down-dp-easy-conci-iutw | Video Solution (Aryan Mittal) - Link in LeetCode Profile\nMaximum Value of K Coins From Piles by Aryan Mittal\n\n\n\n# Approach & Intution\n\n\n\n\n\n\n\n\n\n# | aryan_0077 | NORMAL | 2023-04-15T01:36:20.982860+00:00 | 2023-04-15T12:50:52.382700+00:00 | 19,424 | false | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Maximum Value of K Coins From Piles` by `Aryan Mittal`\n\n\n\n# Approach & Intution\n, explained | python-dp-solution-complexity-updated-ex-1l4n | Let use dp with states dp(n, k), where it is (current index of pile, nubmer of elements we still need to take). Then on each state we can try to take 0, ..., mi | dbabichev | NORMAL | 2022-03-27T04:00:38.532221+00:00 | 2022-03-27T16:51:47.516775+00:00 | 5,876 | false | Let use dp with states `dp(n, k)`, where it is `(current index of pile, nubmer of elements we still need to take)`. Then on each state we can try to take `0, ..., min(k, len(piles[m]))` elements from pile `m`. Also if `n == N`, that is we reached the last pile and `k == 0`, we are happy, return `0`. If `k > 0`, it mean... | 68 | 1 | ['Dynamic Programming'] | 13 |
maximum-value-of-k-coins-from-piles | Again Knapsack Variation | Easy to understand | again-knapsack-variation-easy-to-underst-ifa0 | TC - O(NM) n=size of piles, m=size of piles[i]\nJAVA\n\nclass Solution {\n Integer dp[][];\n\n public int maxValueOfCoins(List<List<Integer>> piles, int k | surajthapliyal | NORMAL | 2022-03-27T04:00:46.268121+00:00 | 2022-03-28T06:42:10.756937+00:00 | 5,563 | false | TC - O(N*M) n=size of piles, m=size of piles[i]\n**JAVA**\n```\nclass Solution {\n Integer dp[][];\n\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n this.dp = new Integer[piles.size() + 1][k + 1];\n return solve(0, piles, k);\n }\n\n private int solve(int index, List<List<In... | 37 | 1 | ['Memoization'] | 2 |
maximum-value-of-k-coins-from-piles | ✅ C++ | DP + Memoization | c-dp-memoization-by-chandanagrawal23-zglu | \nclass Solution\n{\n public:\n int maxValueOfCoins(vector<vector < int>> &p, int k)\n {\n int n = p.size();\n vector<vec | chandanagrawal23 | NORMAL | 2022-03-27T04:15:03.112649+00:00 | 2022-03-27T04:18:59.196394+00:00 | 5,153 | false | ```\nclass Solution\n{\n public:\n int maxValueOfCoins(vector<vector < int>> &p, int k)\n {\n int n = p.size();\n vector<vector < int>> dp(n + 1, vector<int> (k + 1, -1));\n return solve(0, dp, p, k);\n }\n int solve(int index, vector<vector < int>> &dp, v... | 31 | 3 | ['Dynamic Programming', 'Memoization'] | 5 |
maximum-value-of-k-coins-from-piles | Recursion->Top Down-> Bottom Up || Easy to understand code | recursion-top-down-bottom-up-easy-to-und-xlqb | RECURSION, TLE\n\nclass Solution {\npublic:\n //startPileIdx is always 0\n //piles under consideration for each call ==> [pileIdx = 0 to pileIdx = endPile | mohakharjani | NORMAL | 2023-04-15T01:00:16.009637+00:00 | 2023-04-15T04:02:37.948115+00:00 | 6,698 | false | ### RECURSION, TLE\n```\nclass Solution {\npublic:\n //startPileIdx is always 0\n //piles under consideration for each call ==> [pileIdx = 0 to pileIdx = endPileIdx]\n int solve(vector<vector<int>>&piles, int endPileIdx, int k)\n {\n if (endPileIdx < 0 || k == 0) return 0;\n \n int curr... | 24 | 0 | ['Dynamic Programming', 'C', 'C++'] | 3 |
maximum-value-of-k-coins-from-piles | [Java] Bottom up DP with clear explanation and code | java-bottom-up-dp-with-clear-explanation-53n5 | Either pick all k from previous piles, or choose j from current pile and pick k-j from previous piles\nRecurrence relation:\nf(n,k) represents the max sum of co | gonpachiro | NORMAL | 2022-03-27T04:03:09.065420+00:00 | 2022-03-30T11:35:18.862281+00:00 | 2,319 | false | Either pick all k from previous piles, or choose j from current pile and pick k-j from previous piles\n**Recurrence relation**:\n`f(n,k)` represents the max sum of coins collected from first `n` piles and choosing `k` top coins.\n```\nf(n,k) = max(\n\t\t\tf(n-1,k) // pick k from previous n-1 piles\n\t\t\t,max(f(n-1,k-j... | 24 | 0 | ['Dynamic Programming', 'Java'] | 3 |
maximum-value-of-k-coins-from-piles | ✅ Easy DP Solution/Approach Explained 📝 | Beginner Friendly | easy-dp-solutionapproach-explained-begin-xyxl | Intuition\nThe intuition here is to understand that when we are on any currentPile we have two choices\n- either to exclude that pile and move on to next one or | nikeMafia | NORMAL | 2023-04-15T05:47:29.096829+00:00 | 2023-05-01T06:29:27.399271+00:00 | 3,566 | false | # Intuition\nThe intuition here is to understand that when we are on any currentPile we have two choices\n- either to exclude that pile and move on to next one or\n- pick from currentPile one or two or three coins and so on till <= K(coinsLeft to pick) and currentPile is not exhausted of coins and then move on to new p... | 23 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Java'] | 2 |
maximum-value-of-k-coins-from-piles | C++ | Recursive DP + Memoization | Prefix Sum | Commented Code | c-recursive-dp-memoization-prefix-sum-co-ib9e | Code\n\nclass Solution {\npublic:\n const int inf = 1e9;\n int dp[1001][2001];\n int help(int idx, int k, vector<vector<int>> &piles)\n {\n / | jatin1510 | NORMAL | 2023-04-15T06:11:49.347353+00:00 | 2023-04-15T06:42:30.471228+00:00 | 4,009 | false | # Code\n```\nclass Solution {\npublic:\n const int inf = 1e9;\n int dp[1001][2001];\n int help(int idx, int k, vector<vector<int>> &piles)\n {\n // if no coins left then return 0\n if (k == 0)\n return 0;\n\n // if we have processed all the piles\n if (idx == piles.siz... | 18 | 4 | ['Array', 'Dynamic Programming', 'Prefix Sum', 'C++'] | 1 |
maximum-value-of-k-coins-from-piles | Explained Solution by relating it to coin change problem || Memoisation || C++ | explained-solution-by-relating-it-to-coi-z9sd | Intution and Relation with Coin Change\nLets try to recall what do we do in coin change , we go to every index and either pick or not pick the element.\nSimilar | ankursharma6084 | NORMAL | 2022-03-27T09:12:47.695705+00:00 | 2022-03-27T17:17:00.214713+00:00 | 1,459 | false | ### **Intution and Relation with Coin Change**\nLets try to recall what do we do in coin change , we go to every index and either pick or not pick the element.\nSimilarly , in this question , we go to every index and because we can pick atmost k elements so , we try all the possibilities of picking elements from 0 to m... | 18 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 10 |
maximum-value-of-k-coins-from-piles | 2D DP | 2d-dp-by-votrubac-n06k | We search and memoize the maximum value for k coins and i piles. \n\nC++\ncpp\nint dp[1001][2001] = {};\nint maxValueOfCoins(vector<vector<int>>& piles, int k, | votrubac | NORMAL | 2022-03-27T04:01:13.115225+00:00 | 2022-03-27T04:35:25.570635+00:00 | 2,736 | false | We search and memoize the maximum value for `k` coins and `i` piles. \n\n**C++**\n```cpp\nint dp[1001][2001] = {};\nint maxValueOfCoins(vector<vector<int>>& piles, int k, int i = 0) {\n if (i == piles.size() || k == 0)\n return 0;\n if (dp[i][k] == 0)\n for (int j = 0, sum = 0; j <= piles[i].size() ... | 17 | 1 | ['C'] | 4 |
maximum-value-of-k-coins-from-piles | C++,Top-Down(Memoization) with Explanation. | ctop-downmemoization-with-explanation-by-wyzw | Approach:-\n-->This is the DP Approach with Memoization.\n-->We have Choices for any i\'th index Pile. :-\n 1)Either We should not take any Coin from i\'th ind | bnb_2001 | NORMAL | 2022-03-27T13:27:09.794152+00:00 | 2023-04-15T03:31:37.935521+00:00 | 1,300 | false | **Approach:-**\n-->This is the **DP Approach with Memoization.**\n-->We have Choices for any i\'th index Pile. :-\n 1)Either We should not take any Coin from i\'th index pile.\n 2)Either we take one top coin from it.\n 3)Either we take 2 consecutive top coin from that pile.\n And So ...on \n -->And After that We call ... | 16 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 1 |
maximum-value-of-k-coins-from-piles | ✅Simple DP Solution | Go | C#✅ | simple-dp-solution-go-c-by-shukhratutabo-o3lr | Go\n\nfunc maxValueOfCoins(piles [][]int, k int) int {\n\tmemo := make([][]int, len(piles)+1)\n\tfor i := range memo {\n\t\tmemo[i] = make([]int, k+1)\n\t}\n\n\ | shukhratutaboev | NORMAL | 2023-04-15T00:47:04.514923+00:00 | 2023-04-15T05:58:27.279561+00:00 | 1,102 | false | Go\n```\nfunc maxValueOfCoins(piles [][]int, k int) int {\n\tmemo := make([][]int, len(piles)+1)\n\tfor i := range memo {\n\t\tmemo[i] = make([]int, k+1)\n\t}\n\n\treturn dp(piles, memo, 0, k)\n}\n\nfunc dp(piles [][]int, memo [][]int, i int, k int) int {\n\tif k == 0 || i == len(piles) {\n\t\treturn 0\n\t}\n\tif memo[... | 13 | 1 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Go', 'C#'] | 0 |
maximum-value-of-k-coins-from-piles | C++ Top-down DP | c-top-down-dp-by-lzl124631x-7le5 | See my latest update in repo LeetCode\n\n\n## Solution 1. Top-down DP\n\nLet dp[i][j] be the max value of j coins using piles i ~ N-1. The answer is dp[0][k].\n | lzl124631x | NORMAL | 2022-03-27T04:00:44.368247+00:00 | 2022-03-27T04:00:44.368275+00:00 | 1,816 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n\n## Solution 1. Top-down DP\n\nLet `dp[i][j]` be the max value of `j` coins using piles `i ~ N-1`. The answer is `dp[0][k]`.\n\nFor `dp[i][j]`, we can try using `t` elements from `A[i]` (`0 <= t <= min(j, A[i].size())`), getting `A[i][0... | 12 | 1 | [] | 3 |
maximum-value-of-k-coins-from-piles | ✅ Recursion | Memoization | Tabulation | C++ | Striver | Beginner friendly solution ✅ | recursion-memoization-tabulation-c-striv-7chq | Intuition\nSimple pick or not pick approach. For pick we run a for loop through the array. \n Describe your first thoughts on how to solve this problem. \n\n# | warrior0331 | NORMAL | 2023-04-15T06:31:49.463450+00:00 | 2023-04-15T11:14:28.332655+00:00 | 1,120 | false | # Intuition\nSimple pick or not pick approach. For pick we run a for loop through the array. \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)$... | 11 | 1 | ['C++'] | 1 |
maximum-value-of-k-coins-from-piles | [Python] Bottom-up DP solution | python-bottom-up-dp-solution-by-xil899-9e7f | Intuition\nBottom-up dynamic programming.\n\n\nExplanation\nTop-down DP solution is well-explained in @lee215\'s post. Here we present the Bottom-up DP solution | xil899 | NORMAL | 2022-03-27T18:54:07.552028+00:00 | 2022-09-20T04:25:13.884128+00:00 | 1,397 | false | **Intuition**\nBottom-up dynamic programming.\n\n\n**Explanation**\nTop-down DP solution is well-explained in @lee215\'s [post](https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/discuss/1887010/JavaC%2B%2BPython-Top-down-DP-solution). Here we present the Bottom-up DP solution.\n`dp[i][j]` is the maximum... | 11 | 0 | ['Dynamic Programming', 'Python', 'Python3'] | 4 |
maximum-value-of-k-coins-from-piles | 🔥 [LeetCode The Hard Way] 🔥 DP + Memo Explained | leetcode-the-hard-way-dp-memo-explained-5ttjk | Let dp[i][j] be the maximum total value we can have if we pick j elements starting from piles[i]. The answer is dp[0][k]. First we calculate the value if we pic | __wkw__ | NORMAL | 2023-04-15T04:02:25.439230+00:00 | 2023-04-26T15:21:26.348675+00:00 | 842 | false | Let `dp[i][j]` be the maximum total value we can have if we pick `j` elements starting from `piles[i]`. The answer is `dp[0][k]`. First we calculate the value if we pick any elements in the current pile. Then we try to pick at most `min((int) piles[i].size(), k)` elements and find out the max result.\n\n```cpp\nclass S... | 9 | 0 | ['Dynamic Programming', 'Memoization', 'Python', 'C++'] | 0 |
maximum-value-of-k-coins-from-piles | JAVA || Easy Solution || DP || | java-easy-solution-dp-by-shivrastogi-aegf | \n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int numPiles = piles.siz | shivrastogi | NORMAL | 2023-04-15T00:58:03.735431+00:00 | 2023-04-15T00:58:03.735463+00:00 | 1,701 | false | \n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n int numPiles = piles.size();\n \n int[][] dp = new int[numPiles+1][k+1];\n \n for(int i=1; i<=numPiles; i++){\n for(int j=1; j<=k; j++){\n ... | 9 | 2 | ['Java'] | 1 |
maximum-value-of-k-coins-from-piles | DP | Memoization | Easy to understand | dp-memoization-easy-to-understand-by-nim-i8ug | In the problem, we have to select *K coins from the given piles of coins. In one step we can select one coin from the top of the n piles.\nOur task is to maximi | nimitdidwania27 | NORMAL | 2022-06-10T19:01:00.539051+00:00 | 2022-06-10T19:02:24.583220+00:00 | 695 | false | In the problem, we have to select ****K**** coins from the given piles of coins. In one step we can select one coin from the top of the n piles.\nOur task is to ****maximize the total money we can get****.\nFrom the ith pile, we can select between 0 to k coins.\nTherefore, for every pile we have choice to take 0 coin t... | 9 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.