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-coins-from-k-consecutive-bags
[Python3] binary search
python3-binary-search-by-ye15-wfz5
IntuitionThis is essentially a line sweep problem. However, due to the large values, one cannot calcualte the numbers naively. Instead, we could leverage on pre
ye15
NORMAL
2025-01-05T04:03:32.996726+00:00
2025-01-05T04:16:21.363274+00:00
2,177
false
# Intuition This is essentially a line sweep problem. However, due to the large values, one cannot calcualte the numbers naively. Instead, we could leverage on prefix sum and binary search to make the calculations more efficiently. # Approach We first sort `coins` and calculate the prefix sum of coins. Due to the nat...
19
0
['Python3']
1
maximum-coins-from-k-consecutive-bags
Sorting + PrefixSum + Binary Search - O(nlogn)
sorting-prefixsum-binary-search-onlogn-b-82py
IntuitionThe key observation is that the interval we are looking for will always either start with one of the intervals containing coins or end at one of these
aashishrt7
NORMAL
2025-01-05T06:46:32.107001+00:00
2025-01-05T06:46:32.107001+00:00
2,253
false
# Intuition The key observation is that the interval we are looking for will always either start with one of the intervals containing coins or end at one of these intervals. Based on this, we can handle the problem in two cases: 1. Starting with a Coin Interval: For each coin-containing interval, assume it as the star...
18
0
['C++']
2
maximum-coins-from-k-consecutive-bags
[Python] Sliding Window
python-sliding-window-by-awice-i1sv
Let the intervals be [li​,ri​,wi​].The final interval I must have Ileft​=li​ or Iright​=ri​. We can deduce this by imagining we are sliding the interval left o
awice
NORMAL
2025-01-05T04:29:40.179786+00:00
2025-01-05T04:30:05.566235+00:00
1,310
false
Let the intervals be $[l_i, r_i, w_i]$. The final interval $\bold{I}$ must have $\bold{I}_\text{left} = l_i$ or $\bold{I}_\text{right} = r_i$. We can deduce this by imagining we are sliding the interval left or right. Only the intersection of $\bold{I}$ with the first or last intervals in $A$ will be affected. To s...
16
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Sliding Window
sliding-window-by-votrubac-fjkq
This problem is tricky to implement due to edge cases.Intuition: the consecutive bags "window" is aligned with either start (left-aligned) or end (right-aligned
votrubac
NORMAL
2025-01-05T06:42:29.552066+00:00
2025-01-05T07:02:25.376830+00:00
1,847
false
This problem is tricky to implement due to edge cases. **Intuition:** the consecutive bags "window" is aligned with either start (left-aligned) or end (right-aligned) of an interval. We sort the intervals, and go left-to-right maintaining the total `sum` in the window. For intervals in the window, we first check the...
9
0
['C++']
3
maximum-coins-from-k-consecutive-bags
Perfectly Explained Code || With Proof || Greedy Approach || O(N logN) Time
perfectly-explained-code-with-proof-gree-q2j7
IntuitionTake any subarray of length k to maximize coins, I thought either start at l[i] or r[i] but that seemed to be incorrect, later on I thought to also co
Rahul_Gupta07
NORMAL
2025-01-05T04:43:59.303186+00:00
2025-01-05T19:13:39.839182+00:00
1,041
false
# Intuition Take any subarray of length k to maximize coins, I thought either start at l[i] or r[i] but that seemed to be incorrect, later on I thought to also consider the fact that either end at l[i] or r[i], then I proved it (check out in code), that it was the approach required. # Approach Explained through comme...
7
0
['Binary Search', 'Greedy', 'Prefix Sum', 'C++']
2
maximum-coins-from-k-consecutive-bags
Simple Solution
simple-solution-by-noobiiitian-by86
Code
noobiiitian
NORMAL
2025-01-05T09:50:47.647511+00:00
2025-01-05T09:50:47.647511+00:00
676
false
# Code ```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, long long k) { // Sort coins intervals by their start time sort(coins.begin(), coins.end()); queue<vector<long long>> q; // Store intervals: [start, end, coins] long long sum = 0; //...
6
1
['C++']
0
maximum-coins-from-k-consecutive-bags
1.5hrs after contest ends...
15hrs-after-contest-ends-by-jmucc314-5c6v
I'm tiredIntuitionI first thought to sort the coins by where they start since that would make iterating through them sensible. Originally I thought to loop thro
jmucc314
NORMAL
2025-01-05T05:55:32.387863+00:00
2025-01-05T05:55:32.387863+00:00
506
false
I'm tired # Intuition I first thought to sort the coins by where they start since that would make iterating through them sensible. Originally I thought to loop through every possibile starting index but that was too slow. Then I thought of course I can just only take ranges that start at the start of a coin range. Exc...
5
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Java | Fixing Start/End - Prefix | Sliding Window | 2 - Approaches
java-fixing-startend-prefix-sliding-wind-08ak
IntuitionTry to Fix the one position(start/end) and other postion will be ((start+k-1)/end-k+1) and for that postion find the index from coins segment and get t
monukumar012
NORMAL
2025-01-05T07:50:38.831006+00:00
2025-01-05T07:59:43.307389+00:00
766
false
# Intuition Try to Fix the one position(start/end) and other postion will be ((start+k-1)/end-k+1) and for that postion find the index from coins segment and get the sum between them using prefix # Approach 1 For Each Coins Segement fixed start and end if **we fixed the start then our end will be start+k-1** and for r...
4
0
['Two Pointers', 'Sliding Window', 'Prefix Sum', 'Java']
1
maximum-coins-from-k-consecutive-bags
Sliding Window
sliding-window-by-dplopez-z4cl
ApproachTechniques Used The code uses several key techniques to solve the problem efficiently while ensuring all possible valid windows are considered: Sorting
dplopez
NORMAL
2025-01-05T05:09:43.053122+00:00
2025-01-05T05:09:43.053122+00:00
128
false
# Approach Techniques Used The code uses several key techniques to solve the problem efficiently while ensuring all possible valid windows are considered: 1. Sorting the Intervals The intervals are sorted by their start points (l) to process them in ascending order. This helps in iterating over the intervals and calc...
4
0
['JavaScript']
0
maximum-coins-from-k-consecutive-bags
General templates for sliding on non-overlapping intervals
general-templates-for-sliding-on-non-ove-qdp2
Use the following functions for sliding window problems having non-overlapping intervals regardless of whether each interval has a cost(weight) or not.CodeCompl
lokeshwar777
NORMAL
2025-01-13T17:01:32.950974+00:00
2025-01-13T17:14:20.312138+00:00
284
false
Use the following functions for sliding window problems having non-overlapping intervals regardless of whether each interval has a cost(weight) or not. # Code ```cpp [] #define ll long long #define cost(x) ((vec[x].size()>2)?vec[x][2]:1) class Solution { public: ll slide(vector<vector<int>>& vec, int k){ // non-ov...
3
0
['Sliding Window', 'Sorting', 'C++', 'Python3']
1
maximum-coins-from-k-consecutive-bags
An elegant two-pass sliding window solution with O(n log n) time complexity
an-elegant-two-pass-sliding-window-solut-ptvw
Intuition The problem involves finding a k-length segment on a number line that collects the maximum possible coins from overlapping segments. Since we need to
sorenramesh868
NORMAL
2025-01-08T11:36:33.764328+00:00
2025-01-08T11:36:33.764328+00:00
140
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> - The problem involves finding a k-length segment on a number line that collects the maximum possible coins from overlapping segments. - Since we need to consider how segments overlap with our k-length window, we can use a sliding window a...
3
0
['Sliding Window', 'C++']
0
maximum-coins-from-k-consecutive-bags
2 Sliding windows || O(n)
2-sliding-windows-on-by-ayush34513-82n5
IntuitionThe only fear we all have is the window is using partial ranges in left and right. (left and right denoting index of ranges that we are now considering
Ayush34513
NORMAL
2025-01-05T04:44:54.040423+00:00
2025-01-05T09:02:30.657210+00:00
644
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The only fear we all have is the window is using partial ranges in left and right. (left and right denoting index of ranges that we are now considering ) i.e some complete ranges and at right and left end we arre having some partial values ...
3
0
['Two Pointers', 'Sliding Window', 'C++']
3
maximum-coins-from-k-consecutive-bags
C++ Bruteforce-sorta + Binary Search
c-bruteforce-sorta-binary-search-by-bram-bf20
Complexity Time complexity: O(n∗log(n)) Space complexity: O(n) Code
bramar2
NORMAL
2025-01-05T04:03:22.466419+00:00
2025-01-05T04:03:22.466419+00:00
734
false
# Complexity - Time complexity: $O(n*log(n))$ - Space complexity: $O(n)$ # Code ```cpp [] #include <bits/stdc++.h> using namespace std; class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { sort(coins.begin(), coins.end()); int n = coins.size(); vector pre(...
3
0
['C++']
0
maximum-coins-from-k-consecutive-bags
AVS
avs-by-vishal1431-necq
null
Vishal1431
NORMAL
2025-01-06T17:50:15.324067+00:00
2025-01-06T17:50:15.324067+00:00
51
false
```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { long long ret{0}; sort(coins.begin(), coins.end()); long long sum = 0; for (int i = 0, j = 0; i < coins.size(); ++i) { int lim = coins[i][0] + k; for (; j < coins....
2
0
['Array', 'Greedy', 'Sliding Window', 'Sorting', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
Well commented code. Sliding window approach | Python
well-commented-code-sliding-window-appro-hhey
Code
tailtit
NORMAL
2025-01-06T07:08:07.079167+00:00
2025-01-06T07:08:07.079167+00:00
188
false
# Code ```python3 [] class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: ans = 0 s = 0 coins.sort() # Sort the coins by the start of each range j = 0 for i in range(len(coins)): l, r, c = coins[i] # Extract the left, right, an...
2
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Binary Search || Beats 100.00%
binary-search-beats-10000-by-ahmedsayed1-fec1
ApproachAn optimal starting position for k consecutive bags will be either li or ri - k + 1.Code
AhmedSayed1
NORMAL
2025-01-06T00:53:52.459513+00:00
2025-01-06T00:53:52.459513+00:00
246
false
# Approach <h3>An optimal starting position for k consecutive bags will be either li or ri - k + 1.</h3> # Code ```cpp [] #define ll long long class Solution { public: long long maximumCoins(vector<vector<int>>& x, int k) { ll ans = 0, n = x.size(); x.insert(x.begin(), {0}); sort(x.begin...
2
0
['Binary Search', 'Greedy', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
Maximum Coins From K Consecutive Bags | Sliding Window | C++
maximum-coins-from-k-consecutive-bags-sl-uprn
Code
JeetuGupta
NORMAL
2025-01-05T10:00:59.022261+00:00
2025-01-05T10:00:59.022261+00:00
224
false
# Code ```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { sort(coins.begin(), coins.end()); vector<vector<int>> a; int start = coins[0][0]; if(start > 1){ a.push_back({1, start - 1, 0}); } int last = start - 1;...
2
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Sliding window. Optimal solution
sliding-window-by-xxxxkav-h1vz
null
xxxxkav
NORMAL
2025-01-28T21:25:52.453539+00:00
2025-01-28T22:55:02.154468+00:00
90
false
``` class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: coins.sort(key = itemgetter(0)) i, total, ans, n = 0, 0, 0, len(coins) l0, r0, c0 = coins[0] for l, r, c in coins: while i < n and r - coins[i][0] + 1 >= k: l0, r0, c0 ...
1
0
['Sliding Window', 'Python3']
0
maximum-coins-from-k-consecutive-bags
For my reference...
for-my-reference-by-user8034yc-wgz1
IntuitionApproachComplexity Time complexity: Space complexity: Code
user8034Yc
NORMAL
2025-01-13T09:20:57.578989+00:00
2025-01-13T09:20:57.578989+00:00
28
false
# Intuition <!-- sort the coins and consider window (L,R C) that are valid (meaning the window size is < k). If added new range of L to R cause window invalid, consider the total obtain by including a much as possible before remove coins from start of window. --> # Approach <!-- 1) Sort the coins to obtain the ascendi...
1
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
C++ || Sorting + Sliding Window
c-sorting-sliding-window-by-mr_mv-uyzz
Complexity Time complexity: O(N∗Log(N)) O(N∗Log(N)) For sorting O(3∗N) For calculating maximum coins Total : O(N∗Log(N))+O(3∗N)≈O(N∗Log(N)) Space compl
Mr_mv
NORMAL
2025-01-09T08:57:03.893477+00:00
2025-01-09T09:08:53.488084+00:00
179
false
# Complexity - Time complexity: $$O(N*Log(N))$$ - - $$O(N*Log(N))$$ For sorting - - $$O(3*N)$$ For calculating maximum coins Total : $$O(N*Log(N)) + O(3*N) ≈ O(N*Log(N)) $$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(1)$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Co...
1
0
['Array', 'Greedy', 'Sliding Window', 'Sorting', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
Python Two Pointers
python-two-pointers-by-antrixm-fecy
IntuitionEither start or end of the segment aligns with the start or end of any one interval respectively.Start from the interval which aligns and keep on addin
antrixm
NORMAL
2025-01-07T05:24:56.452360+00:00
2025-01-07T05:24:56.452360+00:00
44
false
# Intuition Either start or end of the segment aligns with the start or end of any one interval respectively. Start from the interval which aligns and keep on adding intervals if they are fully in the range and at last, add the partial interval. Do the same in the reversed order too. # Complexity - Time complexity: ...
1
0
['Two Pointers', 'Sorting', 'Python3']
0
maximum-coins-from-k-consecutive-bags
Simple Solution - Sliding window [100% runtime]
simple-solution-sliding-window-100-runti-of39
ApproachIn a subarray, if you have the option to choose between two elements, you would naturally shift the window towards the bag with the maximum weight and a
risky_coder
NORMAL
2025-01-05T18:24:39.234250+00:00
2025-01-05T18:24:39.234250+00:00
140
false
# Approach In a subarray, if you have the option to choose between two elements, you would naturally shift the window towards the bag with the maximum weight and aim to select elements from that bag. Therefore, consider all possible starting bags for the subarray in both the forward and reverse arrays. # Complexity -...
1
0
['Two Pointers', 'Greedy', 'Sliding Window', 'Sorting', 'C++']
0
maximum-coins-from-k-consecutive-bags
find Max fromm k consecutive bags
find-max-fromm-k-consecutive-bags-by-sha-i6kp
IntuitionAnalyse that it is better to take start point as either start of interval or end of intervalApproachsort to ensure the intervals are sequential in natu
shashankpant
NORMAL
2025-01-05T12:39:54.215672+00:00
2025-01-05T12:39:54.215672+00:00
71
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Analyse that it is better to take start point as either start of interval or end of interval # Approach <!-- Describe your approach to solving the problem. --> sort to ensure the intervals are sequential in nature sliding window once form...
1
0
['C++']
0
maximum-coins-from-k-consecutive-bags
O(n) and O(1) space 2 sliding windows solution in 1 pass
on-and-o1-space-2-sliding-windows-soluti-jfri
IntuitionThe problem gives the hint of sliding window based on that once {l,r} is sorted, any range that lies beyond r, will not have any index to the currentLe
01DP
NORMAL
2025-01-05T10:03:00.142564+00:00
2025-01-05T10:03:00.142564+00:00
60
false
# Intuition The problem gives the hint of sliding window based on that once {l,r} is sorted, any range that lies beyond r, will not have any index to the currentLeft, where currentLeft is the leftmost index one can pick to satisfy the range till r. # Approach In addition to the above sliding window idea, we need to co...
1
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Maximum Coins Collection from Intervals with Fixed Subarray Size
maximum-coins-collection-from-intervals-rlcr5
IntuitionTo solve the problem of maximizing the number of coins collected from given intervals with a fixed size k, we can leverage sorting, prefix sums, and bi
rthakur2712
NORMAL
2025-01-05T09:23:31.612533+00:00
2025-01-05T09:23:31.612533+00:00
45
false
### Intuition <!-- Describe your first thoughts on how to solve this problem. --> To solve the problem of maximizing the number of coins collected from given intervals with a fixed size `k`, we can leverage sorting, prefix sums, and binary search. Sorting helps structure the intervals in a logical order, prefix sum...
1
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Java | Fixing Start/End - Prefix | Sliding Window | 2 - Approaches
java-fixing-startend-prefix-sliding-wind-60v1
IntuitionTry to Fix the one position(start/end) and other postion will be ((start+k-1)/end-k+1) and for the postion find the index from coins segment and get th
monukumar012
NORMAL
2025-01-05T07:50:33.703614+00:00
2025-01-05T07:50:33.703614+00:00
143
false
# Intuition Try to Fix the one position(start/end) and other postion will be ((start+k-1)/end-k+1) and for the postion find the index from coins segment and get the sum between them using prefix # Approach 1 For Each Coins Segement fixed start and end if **we fixed the start then our end will be start+k-1** and for re...
1
0
['Two Pointers', 'Sliding Window', 'Prefix Sum', 'Java']
0
maximum-coins-from-k-consecutive-bags
Python - Binary Search with Prefix Sums [TC: O(n*log(n)) SC: O(n)]
python-binary-search-with-prefix-sums-tc-gppd
Complexity Time complexity: O(n∗log(n)) Space complexity: O(n) Code
alexpods
NORMAL
2025-01-05T04:04:46.585396+00:00
2025-01-05T04:04:46.585396+00:00
183
false
# Complexity - Time complexity: $$O(n*log(n))$$ - Space complexity: $$O(n)$$ # Code ```python3 [] class Solution(object): def maximumCoins(self, coins, k): coins.sort(key=lambda x: x[0]) xx = [-int(1e10)] cc = [0] ss = 0 for l,r,c in coins: xx += [l] ...
1
0
['Binary Search', 'Python3']
0
maximum-coins-from-k-consecutive-bags
Sliding window with a lot of corner cases
sliding-window-with-a-lot-of-corner-case-3jfw
IntuitionConstraints won't let us slide the whole coordinate line. Let's slide intervals instead.ApproachFirst, sort the intervals to process them in order.We h
whoawhoawhoa
NORMAL
2025-01-05T04:03:14.941873+00:00
2025-01-05T04:09:20.830863+00:00
658
false
# Intuition Constraints won't let us slide the whole coordinate line. Let's slide intervals instead. # Approach First, sort the intervals to process them in order. We have 5 different options in general. 1. Length of an interval is more than `k`. 2. Current window length is less than `k`, but we can fill it with curr...
1
0
['Sliding Window', 'Line Sweep', 'Sorting', 'Java']
0
maximum-coins-from-k-consecutive-bags
[C++] binary search, only consider start and end
binary-search-c-by-ziang142019-ficn
Code
ziang142019
NORMAL
2025-01-05T04:03:10.832442+00:00
2025-01-05T04:08:12.323900+00:00
298
false
# Code ```cpp [] #define FOR(i,a,b) for(int i = a; i < b.size(); ++i) #define F(i,a,b) for(int i = a; i < b; ++i) #define F0(i,b) for(int i = 0; i< b.size();++i) #define BE(a) a.begin(), a.end() #define __S(a) a.size() #define pb(a) push_back(a) #define pr(a) cout << a << " "; ty...
1
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Only consider interval starts and ends for window
only-consider-interval-starts-and-ends-f-vccs
null
theabbie
NORMAL
2025-01-05T04:01:37.116586+00:00
2025-01-05T04:01:37.116586+00:00
471
false
```python3 [] class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: n = len(coins) coins.sort() p = [0] * (n + 1) for i in range(n): p[i + 1] = p[i] + coins[i][2] * (coins[i][1] - coins[i][0] + 1) starts = set() for l, r, c in coin...
1
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Sliding Window using pure C not C++
sliding-window-using-pure-c-not-c-by-nit-b2ik
IntuitionThere is just one observation/inutition: (whatever) Either the window is starting at Li or ending at Ri. (optimal) In those cases you can get more coin
nitish-pattanaik
NORMAL
2025-03-25T10:30:07.477849+00:00
2025-03-25T10:30:07.477849+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> There is just one observation/inutition: (whatever) - Either the window is starting at `Li` or ending at `Ri`. (optimal) - In those cases you can get more coins. - You can't check just `Li` positions. Because each interval have different co...
0
0
['C']
0
maximum-coins-from-k-consecutive-bags
C++ | Prefix sum + Binary Search
c-prefix-sum-binary-search-by-kena7-ksdi
Code
kenA7
NORMAL
2025-03-04T09:15:43.989795+00:00
2025-03-04T09:15:43.989795+00:00
15
false
# Code ```cpp [] class Solution { public: #define ll long long int LB(vector<vector<int>>& coins, int x) { int n=coins.size(); if(x<coins[0][0]) return -1; if(x>coins[n-1][1]) return n; int l=0,h=n-1,res; while(l<=h) { int ...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Easy to understand!
easy-to-understand-by-saurabhabd_360-45-4d1y
IntuitionApproachComplexity Time complexity: Space complexity: Code
Saurabhabd_360-45
NORMAL
2025-02-17T06:45:51.721394+00:00
2025-02-17T06:45:51.721394+00:00
30
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
['Hash Table', 'Binary Search', 'Sorting', 'Prefix Sum', 'Java']
0
maximum-coins-from-k-consecutive-bags
Rust Solution
rust-solution-by-abhineetraj1-1xru
IntuitionThe goal of this problem is to maximize the total number of coins we can collect within a range of length k. We are given a list of intervals where eac
abhineetraj1
NORMAL
2025-02-13T01:21:34.393910+00:00
2025-02-13T01:21:34.393910+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The goal of this problem is to maximize the total number of coins we can collect within a range of length k. We are given a list of intervals where each interval has a start, end, and the number of coins within that interval. To solve this,...
0
0
['Rust']
0
maximum-coins-from-k-consecutive-bags
O(nlogn) Sliding window solution
onlogn-sliding-window-solution-by-judych-eo5z
IntuitionApproachComplexity Time complexity: O(nlogn) for sort() Space complexity: O(1) Code
JudyCheung
NORMAL
2025-01-20T22:38:07.259279+00:00
2025-01-20T22:38:07.259279+00:00
37
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(nlogn) for sort() <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e....
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Easy Java Solution || Sliding Interval Window
easy-java-solution-sliding-interval-wind-1no6
IntuitionApproachComplexity Time complexity: Space complexity: Code
ravikumar50
NORMAL
2025-01-20T19:10:49.016939+00:00
2025-01-20T19:10:49.016939+00:00
58
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
['Java']
0
maximum-coins-from-k-consecutive-bags
Javascript | Sliding Window | O(n)
javascript-sliding-window-on-by-aryonbe-y5gd
Code
aryonbe
NORMAL
2025-01-17T08:13:13.732655+00:00
2025-01-17T08:13:13.732655+00:00
9
false
# Code ```javascript [] /** * @param {number[][]} coins * @param {number} k * @return {number} */ var maximumCoins = function(coins, k) { const n = coins.length; function solve(A){ A.sort((a,b) => a[0] - b[0]); let res = 0, cur = 0, i = 0; for(let j = 0; j < A.length; j++){ ...
0
0
['JavaScript']
0
maximum-coins-from-k-consecutive-bags
Explained sliding window solution [C++/Java/Python/Javascript] || Beats 100%
explained-sliding-window-solution-cjavap-wjqs
IntuitionInput Description: coins is a list of intervals: [𝑠𝑡𝑎rt,end,coins]sorted by their starting index. k is the size of the range (or sliding window) within
be_fighter
NORMAL
2025-01-16T12:14:21.615107+00:00
2025-01-16T12:14:53.099695+00:00
93
false
# Intuition # Input Description: 1. coins is a list of intervals: [𝑠𝑡𝑎rt,end,coins]sorted by their starting index. 2. k is the size of the range (or sliding window) within which we can collect coins. # Overall Goal: 1. For any sliding window of size k, calculate the maximum coins that can be collected. 2. To achie...
0
0
['Array', 'Binary Search', 'Greedy', 'Sliding Window', 'Sorting', 'Prefix Sum', 'Python', 'C++', 'Java', 'JavaScript']
0
maximum-coins-from-k-consecutive-bags
sliding window one pass soln.
sliding-window-one-pass-soln-by-rishiins-3zfo
IntuitionApproachsince the size of the array is 1e9 giving us the idea that computations will not be possible within time thus we pivot to using the intervals f
RishiINSANE
NORMAL
2025-01-15T19:09:50.258826+00:00
2025-01-15T19:09:50.258826+00:00
25
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach since the size of the array is 1e9 giving us the idea that computations will not be possible within time thus we pivot to using the intervals for our calculations hence using sliding window approach over intervals completely and...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Maximum Coins From K Consecutive Bags
maximum-coins-from-k-consecutive-bags-by-z00k
IntuitionApproachSliding WindowComplexity Time complexity:O(N log n) Space complexity:O(1) Code
Subham_Pujari23
NORMAL
2025-01-15T04:46:05.494940+00:00
2025-01-15T04:46:05.494940+00:00
31
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach Sliding Window <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity:O(N log n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:O(1) <!-- Add your space complexity here...
0
0
['Java']
0
maximum-coins-from-k-consecutive-bags
Binary Search prefix sum solution
binary-search-prefix-sum-solution-by-ari-d5wo
IntuitionApproachComplexity Time complexity: Space complexity: Code
Arif2321
NORMAL
2025-01-11T19:30:21.436315+00:00
2025-01-11T19:30:21.436315+00:00
22
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
maximum-coins-from-k-consecutive-bags
Simplest Sliding Window after filling the gaps.
simplest-sliding-window-after-filling-th-qpc2
IntuitionThe problem can become much easier as soon as there is no gaps between intervals. Once we have some continous intervals, we have to choose a segment of
suri_kumkaran
NORMAL
2025-01-11T13:14:12.960008+00:00
2025-01-11T13:14:12.960008+00:00
24
false
# Intuition The problem can become much easier as soon as there is no gaps between intervals. Once we have some continous intervals, we have to choose a segment of intervals such that it's lenght is K. Now the observation is, every optimal segment selection will either start at some interval or end at some interval. ...
0
0
['Sliding Window', 'C++']
0
maximum-coins-from-k-consecutive-bags
Clear Detailed Optimal Solution O(nlogn) (Python)
clear-detailed-optimal-solution-onlogn-p-19nr
IntuitionA key observation to solving this problem is as follows: If we only consider windows which start at the left endpoint of a segment or end at the right
carpenoctem
NORMAL
2025-01-11T09:17:08.639656+00:00
2025-01-11T09:17:08.639656+00:00
35
false
# Intuition A key observation to solving this problem is as follows: If we only consider windows which start at the left endpoint of a segment or end at the right endpoint of a segment, we are guaranteed to find the window with the max number of coins. **This window may not be uniquely optimal (e.g. there may be other ...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
O(n*log(n)) | 2 Pointers | Code Reusebility
onlogn-2-pointers-code-reusebility-by-sa-zofa
IntuitionThe solution will contain atleast "one segment where we take all the bags(at most k) for it"ApproachSort and do 2 pointersComplexity Time complexity: O
sagsango
NORMAL
2025-01-11T08:29:29.680934+00:00
2025-01-11T08:29:29.680934+00:00
16
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The solution will contain atleast "one segment where we take all the bags(at most k) for it" # Approach <!-- Describe your approach to solving the problem. --> Sort and do 2 pointers # Complexity - Time complexity: <!-- Add your time comp...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
lovely_anna
lovely_anna-by-lovely_anna-wrgh
null
lovely_anna
NORMAL
2025-01-11T04:14:12.678823+00:00
2025-01-11T04:14:12.678823+00:00
20
false
```java [] class Solution { public long maximumCoins(int[][] a, int k) { var n = a.length; var sp = new TreeSet<int[]>((x, y) -> Long.compare(x[0], y[0])); var ep = new TreeSet<int[]>((x, y) -> Long.compare(x[0], y[0])); Arrays.sort(a, (x, y) -> x[0] - y[0]); for (var i = 0...
0
0
['Java']
0
maximum-coins-from-k-consecutive-bags
Step by Step | Conceptually Good | Binary Search + Prefix Sum
step-by-step-conceptually-good-binary-se-y9wy
Code
Shivam_Kapoor
NORMAL
2025-01-10T20:35:53.724557+00:00
2025-01-10T20:35:53.724557+00:00
18
false
# Code ```cpp [] #define ll long long class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { ll n = coins.size(); sort(coins.begin(), coins.end()); vector<ll> p(n, 0); p[0] = 1LL * coins[0][2] * (coins[0][1] - coins[0][0] + 1); for(ll i ...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Javascript - Sliding Window
javascript-sliding-window-by-faustaleona-wyex
Code
faustaleonardo
NORMAL
2025-01-09T23:46:16.023399+00:00
2025-01-09T23:46:16.023399+00:00
11
false
# Code ```javascript [] /** * @param {number[][]} coins * @param {number} k * @return {number} */ var maximumCoins = function (coins, k) { coins.sort((a, b) => a[0] - b[0]); let ans = 0; let total = 0; let start = 0; for (let end = 0; end < coins.length; end++) { total += (coins[end][1] - coins[end][...
0
0
['Sliding Window', 'JavaScript']
1
maximum-coins-from-k-consecutive-bags
prefix sum on ranges
prefix-sum-on-ranges-by-joshuadlima-rsqw
Intuitionevery valid segment will either start on li and go upto k forward or end at ri and go k backward. We can use prefix sum to calculate the sum between th
joshuadlima
NORMAL
2025-01-09T21:22:39.263957+00:00
2025-01-09T21:22:39.263957+00:00
15
false
# Intuition every valid segment will either start on li and go upto k forward or end at ri and go k backward. We can use prefix sum to calculate the sum between these ranges and then just bruteforce. # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(nlogn) - Space c...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
c++() forward & backward prefix sum
c-forward-backward-prefix-sum-by-zx007pi-6dn6
IntuitionApproachComplexity Time complexity: Space complexity: Code
zx007pi
NORMAL
2025-01-09T08:18:49.699332+00:00
2025-01-09T08:18:49.699332+00:00
14
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
maximum-coins-from-k-consecutive-bags
Slide window(to left/right)
slide-windowto-leftright-by-linda2024-kidm
Intuition(Be careful type cast in c#)ApproachComplexity Time complexity: Space complexity: Code
linda2024
NORMAL
2025-01-08T22:29:27.626347+00:00
2025-01-08T22:29:27.626347+00:00
21
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> (Be careful type cast in c#) # 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,...
0
0
['C#']
0
maximum-coins-from-k-consecutive-bags
Prefix Sum + Binary Search | Intuition Explained
prefix-sum-binary-search-intuition-expla-z93g
Intuition Maximum coins can be achieved by choosing a starting or ending point of some interval. Hence, we check coins for all starting and ending positions.
adicoder_16
NORMAL
2025-01-08T21:09:51.183439+00:00
2025-01-08T21:09:51.183439+00:00
33
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> - Maximum coins can be achieved by choosing a starting or ending point of some interval. Hence, we check coins for all starting and ending positions. - For all starting and ending points, we check the reach and calculate number of coins in...
0
0
['Binary Search', 'Greedy', 'Sorting', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
[CODE ONLY][DEBUG OUTPUT] PYTHON USING Alex Wice's SLIDING WINDOW SOLUTION
code-onlydebug-output-python-using-alex-tiqgy
Code
greg_savage
NORMAL
2025-01-08T10:22:49.034272+00:00
2025-01-08T10:22:49.034272+00:00
23
false
# Code ```python3 [] # Using Alex Wice's sliding window # https://leetcode.com/problems/maximum-coins-from-k-consecutive-bags/solutions/6232234/python-sliding-window-by-awice-i1sv class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: n = len(coins) def helper(h_coins: Lis...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
My Solutions
my-solutions-by-hope_ma-n0sn
1. Count the coins of the bags either starting from the left end of every segment or ending with the right end of every segment2. Use the sliding window
hope_ma
NORMAL
2025-01-07T10:02:11.540824+00:00
2025-01-07T10:02:11.540824+00:00
13
false
**1. Count the coins of the bags either starting from the left end of every segment or ending with the right end of every segment** ``` /** * Time Complexity: O(n * log(n)) * Space Complexity: O(n) * where `n` is the length of the vector `coins` */ class Solution { private: static constexpr int l_i = 0; static...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
3413. Maximum Coins From K Consecutive Bags(62.88%)
3413-maximum-coins-from-k-consecutive-ba-ccq5
Intuition Represent coin intervals with a difference array-like map. Flatten the data into positions and their respective coin counts using prefix sums. Use a s
Nalindalal2004
NORMAL
2025-01-07T04:27:04.002085+00:00
2025-01-07T04:27:04.002085+00:00
32
false
# Intuition 1. Represent coin intervals with a difference array-like map. 2. Flatten the data into positions and their respective coin counts using prefix sums. 3. Use a sliding window to find the maximum sum of k consecutive positions. <!-- Describe your first thoughts on how to solve this problem. --> # Approach 1....
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Easy Binary Search New Approach
easy-binary-search-new-approach-by-ankii-2ta0
Intuitionwe have given to select k consecutive elements and since for 1e9 we cannot traverse on every index and apply sliding window. So we need to check that f
ankii09102003
NORMAL
2025-01-06T13:30:30.085720+00:00
2025-01-06T13:30:30.085720+00:00
48
false
# Intuition we have given to select k consecutive elements and since for 1e9 we cannot traverse on every index and apply sliding window. So we need to check that for a particular index given in coins array what is the last element and where it lies.So, directy traverse all the ranges given and find the last element whe...
0
0
['Binary Search', 'Sliding Window', 'C++']
0
maximum-coins-from-k-consecutive-bags
PrefixSum and BinarySearch Approach
prefixsum-and-binarysearch-approach-by-h-lb9t
IntuitionIt can be proved that in order to collect maximum coins you need to start at leftMostPoint of interval or end at rightMostPoint of a given interval in
harry161998
NORMAL
2025-01-06T13:26:20.428836+00:00
2025-01-06T13:26:20.428836+00:00
37
false
# Intuition It can be proved that in order to collect maximum coins you need to start at leftMostPoint of interval or end at rightMostPoint of a given interval in case of distinct division of coins in a given interval. # Approach Calculate the prefixSum in order to find totalCoins in O(1) time. Take two case of start...
0
0
['Binary Search', 'Greedy', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
C++ | Beats 100% | Sliding Window | Clean and Concise |
c-beats-100-sliding-window-clean-and-con-elgv
IntuitionI was not able to solve this in contest i was stuck trying sweepline with map hoping for every window of k i can calculate ans but was very hard to imp
n1kh1l
NORMAL
2025-01-06T05:51:58.268348+00:00
2025-01-06T05:51:58.268348+00:00
55
false
# Intuition I was not able to solve this in contest i was stuck trying sweepline with map hoping for every window of k i can calculate ans but was very hard to implement eventually it is sliding window only and hint suggests to do it for every interval but how to prove it, I can only think is there is a gap with 0 valu...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Kotlin || Sliding Window || O(N)
kotlin-sliding-window-on-by-nazmulcuet11-8mkh
IntuitionApproachComplexity Time complexity: Space complexity: Code
nazmulcuet11
NORMAL
2025-01-06T04:29:17.204091+00:00
2025-01-06T04:29:17.204091+00:00
16
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
['Sliding Window', 'Kotlin']
0
maximum-coins-from-k-consecutive-bags
two sliding window. python easy solution.
two-sliding-window-python-easy-solution-ovbdh
Code
yuchuehw
NORMAL
2025-01-06T00:21:05.935618+00:00
2025-01-06T00:23:12.922148+00:00
50
false
# Code ```python3 [] class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: def slide(): ans = covers = 0 left = 0 # left index. use for removal for l,r,c in coins: covers += (r-l+1)*c # in while coins[left][1] <= r-...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
prefix sum + binary search(es). ~850ms. finished 10m late :/.
prefix-sum-binary-searches-finished-10m-qfha3
IntuitionThere are two options to make an optimal choice a) collect bags within range of k starting at a left edge of a coin interval b) collect bags within ran
hama87
NORMAL
2025-01-05T22:06:25.722365+00:00
2025-01-06T00:36:20.544124+00:00
47
false
# Intuition There are two options to make an optimal choice a) collect bags within range of k starting at a left edge of a coin interval b) collect bags within range of k ending at a right edge of a coin interval # Approach pre-compute a prefix sum over all coin intervals that stores the total number of coins containe...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Sliding Window. Same as 2271, but in both ways
sliding-window-same-as-2271-but-in-both-hpawt
IntuitionApproachComplexity Time complexity: Space complexity: Code
srptv
NORMAL
2025-01-05T21:00:58.674952+00:00
2025-01-05T21:00:58.674952+00:00
34
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
['Python3']
0
maximum-coins-from-k-consecutive-bags
Easy iterate on array rather than on axis
easy-iterate-on-array-rather-than-on-axi-x4y4
IntuitionApproachComplexity Time complexity: Space complexity: Code
VISHAL_REDDY_K
NORMAL
2025-01-05T18:44:54.698915+00:00
2025-01-05T18:44:54.698915+00:00
22
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
maximum-coins-from-k-consecutive-bags
Easy iterate on array rather than on axis
easy-iterate-on-array-rather-than-on-axi-dei9
IntuitionApproachComplexity Time complexity: Space complexity: Code
VISHAL_REDDY_K
NORMAL
2025-01-05T18:44:51.967945+00:00
2025-01-05T18:44:51.967945+00:00
15
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
maximum-coins-from-k-consecutive-bags
✅ [Java / C++] | 34ms | Beats 100%, super easy sliding window approach.
beats-100-java-sliding-window-solution-b-jjti
IntuitionThe problem is about finding the maximum number of coins we can collect from k consecutive bags. Using a sliding window approach is optimal because it
Only_Night
NORMAL
2025-01-05T18:21:06.787563+00:00
2025-02-02T01:33:17.197684+00:00
112
false
# Intuition The problem is about finding the maximum number of coins we can collect from k consecutive bags. Using a sliding window approach is optimal because it allows us to efficiently compute and update the sum of coins in the window as it moves across the range. ![Screenshot 2025-01-16 at 04.14.28.png](https://ass...
0
0
['Sliding Window', 'C++', 'Java']
0
maximum-coins-from-k-consecutive-bags
Python Medium
python-medium-by-lucasschnee-tbtp
null
lucasschnee
NORMAL
2025-01-05T18:03:26.879296+00:00
2025-01-05T18:03:26.879296+00:00
39
false
```python3 [] class Solution: def maximumCoins(self, A: List[List[int]], k: int) -> int: ''' try every l endpoint to the right and r endpoint to the left of exactly k size prefix sums (1, 2) (4, 5) ''' A.sort() prev_end = 0 for l, r, c in list(A): ...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
sliding window
sliding-window-by-akbc-80b0
null
akbc
NORMAL
2025-01-05T17:05:14.501093+00:00
2025-01-05T17:05:14.501093+00:00
45
false
```python3 [] class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: coins.sort() n = len(coins) def _solve(coins): ans = j = C = 0 for i, (l, r, c) in enumerate(coins): while j < n and coins[j][1] - l + 1 < k: ...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Simple sliding window
simple-sliding-window-by-risabhuchiha-h1xf
null
risabhuchiha
NORMAL
2025-01-05T16:40:08.860103+00:00
2025-01-05T16:40:08.860103+00:00
44
false
```java [] class Solution { public long maximumCoins(int[][] c, int k) { long ans=0; Arrays.sort(c,(a,b)->a[0]-b[0]); int kk=k; int s=0; long max=0; int j=0; int n=c.length; for(int i=0;i<n;i++){ while(j<n&&c[j][1]-c[i][0]+1<=k){ ...
0
0
['Java']
0
maximum-coins-from-k-consecutive-bags
JavaScript O(nlgn): Just test left and right edges of ranges, with binary search
javascript-onlgn-just-test-left-and-righ-80ts
IntuitionThe best outcome can be obtained with the collection starting from some range's left edge, or ending to some range's right edge.Approach Build two pref
lilongxue
NORMAL
2025-01-05T15:41:53.395167+00:00
2025-01-28T09:40:41.094709+00:00
15
false
# Intuition The best outcome can be obtained with the collection starting from some range's left edge, or ending to some range's right edge. # Approach 1. Build two prefix sums. 2. Go from left to right, trying to start the collection from some range's left edge, and see how far it reaches using binary search. 3. Go fr...
0
0
['JavaScript']
0
maximum-coins-from-k-consecutive-bags
Sorting | 2 - Pointer Sliding Window O(nlogn) Time Complexity
sorting-2-pointer-sliding-window-onlogn-ednoy
Intuition Consider the 2 pointer sliding window. Now if we check greedily we want to maximize by taking whole interval right, we don't want holes. We take inter
yash559
NORMAL
2025-01-05T15:40:09.483928+00:00
2025-01-05T15:40:09.483928+00:00
32
false
# Intuition - Consider the **2 pointer sliding window.** - Now if we check greedily we want to maximize by taking whole interval right, we don't want holes. - We take intervals as whole. - We consider them either as **start of window or ending at window.** - so we have to check both possibilities by **2 pointer sliding...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
step multiple bags when sliding window
step-multiple-bags-when-sliding-window-b-tulr
IntuitionSliding window with 2 pointers (segment on the left and segment on th right).Step reasonable number of bags instead of step for every single bag, becau
jrmwng
NORMAL
2025-01-05T15:38:00.635641+00:00
2025-01-05T15:38:00.635641+00:00
34
false
# Intuition Sliding window with 2 pointers (segment on the left and segment on th right). Step reasonable number of bags instead of step for every single bag, because the problem mentioned many many bags. # Approach Replace `std::vector<std::vector<int>> coins` by `std::vector<std::tuple<int, int, int>> vSegment` t...
0
0
['Two Pointers', 'Sliding Window', 'C++']
0
maximum-coins-from-k-consecutive-bags
JAVA 100% faster than other codes | Easy to understand
java-100-faster-than-other-codes-easy-to-o7th
Code
rishabhParsec
NORMAL
2025-01-05T15:24:54.302825+00:00
2025-01-05T15:24:54.302825+00:00
63
false
# Code ```java [] class Solution { public long maximumCoins(int[][] coins, int k) { int n = coins.length; // Sort intervals by start time Arrays.sort(coins, (a, b) -> a[0] - b[0]); // Prepare start, end, and sum arrays int[] start = new int[n]; int[] end...
0
0
['Java']
0
maximum-coins-from-k-consecutive-bags
431
431-by-itsvijay_y-jlb9
IntuitionApproachComplexity Time complexity: Space complexity: Code
itsvijay_y
NORMAL
2025-01-05T15:17:54.311827+00:00
2025-01-05T15:17:54.311827+00:00
15
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
['JavaScript']
0
maximum-coins-from-k-consecutive-bags
C Solution | Beats 100% | O(n logn) Time Complexity | Pls Upvote
c-solution-beats-100-on-logn-time-comple-1kkl
Code
Ex1sTzx
NORMAL
2025-01-05T14:52:13.651470+00:00
2025-01-05T14:52:13.651470+00:00
11
false
# Code ```c [] #define MAX_N 100005 typedef struct { int l, r, c; } Segment; long long prefix[MAX_N]; int cmp(const void* a, const void* b) { Segment* segA = (Segment*)a; Segment* segB = (Segment*)b; if (segA->l < segB->l) { return -1; } else if (segA->l > segB->l) { return 1; ...
0
0
['C']
0
maximum-coins-from-k-consecutive-bags
C Solution | Beats 100% | O(n logn) Time Complexity | Pls Upvote
c-solution-beats-100-on-logn-time-comple-06oe
Code
Ex1sTzx
NORMAL
2025-01-05T14:52:11.218700+00:00
2025-01-05T14:52:11.218700+00:00
13
false
# Code ```c [] #define MAX_N 100005 typedef struct { int l, r, c; } Segment; long long prefix[MAX_N]; int cmp(const void* a, const void* b) { Segment* segA = (Segment*)a; Segment* segB = (Segment*)b; if (segA->l < segB->l) { return -1; } else if (segA->l > segB->l) { return 1; ...
0
0
['C']
0
maximum-coins-from-k-consecutive-bags
Java | 129 ms | Beats 100 % | Binary Search + Prefix Sum
java-129-ms-beats-100-binary-search-pref-i8mt
IntuitionBinary Search + Prefix SumApproachRan two for loops to calculate the sum of coins. First For loop assumes the ith index to be taken completely and to b
rishit19382
NORMAL
2025-01-05T14:48:20.139995+00:00
2025-01-05T14:49:27.413124+00:00
49
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Binary Search + Prefix Sum # Approach <!-- Describe your approach to solving the problem. --> Ran two for loops to calculate the sum of coins. First For loop assumes the ith index to be taken completely and to be the first of the sequence....
0
0
['Binary Search', 'Java']
0
maximum-coins-from-k-consecutive-bags
Simplest Soln ever possible -> Full Detailed With Comments 🤷‍♀️✔
simplest-soln-ever-possible-full-comment-92x8
IntuitionJust Read the Comments. U will Get it.ApproachComplexity Time complexity: Space complexity: Code
its-raj3
NORMAL
2025-01-05T12:37:57.283447+00:00
2025-01-08T15:46:56.874195+00:00
76
false
# Intuition Just Read the Comments. U will Get it. # 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 ```cpp [] #define ll long long...
0
0
['Array', 'Binary Search', 'Greedy', 'Sliding Window', 'Sorting', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
Clean code....looks pretty....nicely commented
clean-codelooks-prettynicely-commented-b-cqc3
IntuitionThe required answer can only be found if we choose start point of all intervals or the end points of all intervalsApproachUsing sliding window,once fro
niteshsaxena03
NORMAL
2025-01-05T11:23:16.314067+00:00
2025-01-05T11:23:16.314067+00:00
67
false
# Intuition The required answer can only be found if we choose start point of all intervals or the end points of all intervals # Approach Using sliding window,once from front side and then from back side,taking max of both # Complexity - Time complexity: O(nlogn) - Space complexity: O(1) # Code ```cpp [] #define ll...
0
0
['C++']
1
maximum-coins-from-k-consecutive-bags
Clean readable code using HashMaps
implementation-using-hashmaps-by-abhi625-vetm
IntuitionApproachComplexity Time complexity:O(NLogN) Space complexity:O(n) Code :Formatted with ChatGpt
abhi625
NORMAL
2025-01-05T10:28:17.848678+00:00
2025-01-05T10:30:00.302931+00:00
64
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity:$$O(NLogN)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:$$O(n)$$ <!-- Add your space complexity here, e.g. $$...
0
0
['Java']
0
maximum-coins-from-k-consecutive-bags
Sliding Window C++
sliding-window-c-by-vaidantjain-snwr
Code
VaidantJain
NORMAL
2025-01-05T10:26:41.193093+00:00
2025-01-05T10:26:41.193093+00:00
66
false
# Code ```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { sort(coins.begin(),coins.end()); int n = coins.size(); long long ans = 0; int j=0; long long sum=0; for(int i=0;i<n;i++){ while(j<n && coins[j][1]<=coin...
0
0
['Sliding Window', 'C++']
0
maximum-coins-from-k-consecutive-bags
Sorting + PrefixSum + Sliding Window
sorting-prefixsum-sliding-window-by-a_ck-zimq
Intuition At first, I wanted to solve with sliding window for each position, but I cannot do this because the maximum number of range value is 10^9. This soluti
a_ck
NORMAL
2025-01-05T10:06:20.647539+00:00
2025-01-05T10:06:20.647539+00:00
32
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> - At first, I wanted to solve with sliding window for each position, but I cannot do this because the maximum number of range value is 10^9. This solution will get TLE. - I found that I could either choose the start position of coins[i] or ...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
Java Sliding window Two side
java-sliding-window-two-side-by-vigneshr-pxgc
IntuitionApproachComplexity Time complexity: Space complexity: Code
vigneshreddyjulakanti
NORMAL
2025-01-05T07:56:09.596715+00:00
2025-01-05T07:56:09.596715+00:00
30
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
['Python3']
0
maximum-coins-from-k-consecutive-bags
☕ Java solution
java-solution-by-barakamon-3gdd
null
Barakamon
NORMAL
2025-01-05T07:34:36.373251+00:00
2025-01-05T07:34:36.373251+00:00
103
false
![Screenshot_3.png](https://assets.leetcode.com/users/images/08344812-6d74-4df1-ac92-d6b3f70b88c1_1736062468.4523218.png) ```java [] import java.util.Arrays; import java.util.Comparator; class Solution { public long maximumCoins(int[][] coins, int k) { Arrays.sort(coins, Comparator.comparingInt(a -> a[0])...
0
0
['Java']
1
maximum-coins-from-k-consecutive-bags
evulate the interval through two passes
evulate-the-interval-through-two-passes-p8f4m
IntuitionWe should evaluate the windows interval size k through two passes: interval start with l_i interval end with r_i ApproachComplexity Time complexity: S
zoneman
NORMAL
2025-01-05T07:24:37.572460+00:00
2025-01-05T07:24:37.572460+00:00
32
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> We should evaluate the windows interval size k through two passes: 1. interval start with l_i 2. interval end with r_i # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time co...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
using binary search
using-binary-search-by-shivajich-berv
Intuitionfinding a valid maximum possible coins amountApproachUsing the binary search as maximum possible coins amount following increasing propertyComplexity
shivajich
NORMAL
2025-01-05T05:59:10.550721+00:00
2025-01-05T05:59:10.550721+00:00
54
false
# Intuition finding a valid maximum possible coins amount # Approach Using the binary search as maximum possible coins amount following increasing property # Complexity - Time complexity: $$O(nlogn) - Space complexity: - $$O(n) # Code ```cpp [] class Solution { public: // bool comp(vector<int> &a, vector<int>...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
[c++][o(NlogN) solution)
conlogn-solution-by-mumrocks-c1gu
Code
MumRocks
NORMAL
2025-01-05T05:23:18.656095+00:00
2025-01-05T05:23:18.656095+00:00
40
false
# Code ```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { sort(coins.begin(),coins.end()); int sz=coins.size(), idx=-1; vector<long long> ps(sz+1); for (int i=1;i<=sz;i++){ ps[i] = ps[i-1] + 1ll*(coins[i-1][1]-coins[i-1][0]+1)*...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
The key to this problem
the-key-to-this-problem-by-llcourage123-skbo
It is natural to consider using a sliding window and prefix sum for this problem. The main challenge lies in understanding that the edge of the optimal window w
llcourage123
NORMAL
2025-01-05T04:43:29.504142+00:00
2025-01-05T04:43:29.504142+00:00
83
false
It is natural to consider using a sliding window and prefix sum for this problem. The main challenge lies in understanding that the edge of the optimal window will always align with either the left or right edge of a segment. While it is possible for the optimal window to start in the middle of one segment and end in ...
0
0
['Python3']
0
maximum-coins-from-k-consecutive-bags
Easy CPP: Sort, binary search, prefix sum
easy-cpp-by-jpaunikar8-t5eo
IntuitionApproachComplexity Time complexity: Space complexity: Code
jpaunikar8
NORMAL
2025-01-05T04:43:06.942913+00:00
2025-01-05T04:46:28.528152+00:00
66
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
maximum-coins-from-k-consecutive-bags
Sorting + greedy + binary search
sorting-greedy-binary-search-by-maxorgus-gofa
Code
MaxOrgus
NORMAL
2025-01-05T04:38:48.043091+00:00
2025-01-05T04:38:48.043091+00:00
112
false
# Code ```python3 [] class Solution: def maximumCoins(self, coins: List[List[int]], k: int) -> int: coins.sort() starts = [a for a,b,c in coins] ends = [b for a,b,c in coins] vals = [c for a,b,c in coins] pres = [0] for a,b,c in coins: pres.append(c*(b-a...
0
0
['Binary Search', 'Greedy', 'Sorting', 'Python3']
0
maximum-coins-from-k-consecutive-bags
C++ sort then iterate left to right and right to left
c-sort-then-iterate-left-to-right-and-ri-pr60
null
user5976fh
NORMAL
2025-01-05T04:38:27.974894+00:00
2025-01-05T04:38:27.974894+00:00
46
false
```cpp [] class Solution { public: long long maximumCoins(vector<vector<int>>& coins, int k) { long long ans = 0; sort(coins.begin(), coins.end()); vector<vector<long long>> p; long long sum = 0; for (auto& v : coins){ long long nextSum = v[1] - v[0] + 1; ...
0
0
['C++']
0
maximum-coins-from-k-consecutive-bags
java solution using prefix sum and binary search!
java-solution-using-prefix-sum-and-binar-vq0y
IntuitionApproachComplexity Time complexity: Space complexity: Code
abhayrana00018
NORMAL
2025-01-05T04:21:43.477046+00:00
2025-01-05T04:21:43.477046+00:00
133
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
['Binary Search', 'Prefix Sum', 'Java']
0
maximum-coins-from-k-consecutive-bags
C++ | Prefix Sum + Binary Search
prefix-sum-binary-search-by-kizu-x41l
IntuitionApproachComplexity Time complexity: O (n log n) Space complexity: Code
kizu
NORMAL
2025-01-05T04:18:48.046851+00:00
2025-01-05T04:19:40.467535+00:00
154
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O (n log n) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: #define...
0
0
['Binary Search', 'Prefix Sum', 'C++']
0
maximum-coins-from-k-consecutive-bags
beats 100% java
beats-100-java-by-vishall001-9uba
IntuitionApproachComplexity Time complexity: Space complexity: Code
Vishall001
NORMAL
2025-01-05T04:05:05.458954+00:00
2025-01-05T04:05:05.458954+00:00
174
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
['Java']
0
maximum-coins-from-k-consecutive-bags
Align with start or end
align-with-start-or-end-by-lyronly-ns16
IntuitionApproach1 Algin start with each interval 2 ALign end with each interval : here we reverse each interval to make it same as Align with start so we can r
lyronly
NORMAL
2025-01-05T04:04:18.709254+00:00
2025-01-05T04:04:18.709254+00:00
137
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> 1 Algin start with each interval 2 ALign end with each interval : here we reverse each interval to make it same as Align with start so we can reuse the code. # Complexity ...
0
0
['C++']
1
string-without-aaa-or-bbb
Java/C++ (and Python) simple greedy
javac-and-python-simple-greedy-by-votrub-rznk
First, I must note that this problem does not feel like \'Easy\'. The implementation is easy, but the intuition is not. In fact, I spent more time on this probl
votrubac
NORMAL
2019-01-27T04:01:24.412508+00:00
2019-01-27T04:01:24.412629+00:00
17,486
false
First, I must note that this problem does not feel like \'Easy\'. The implementation is easy, but the intuition is not. In fact, I spent more time on this problem then on other \'Medium\' problems in the contest.\n\n- If the initial number of As is greater than Bs, we swap A and B.\n- For each turn, we add \'a\' to our...
189
5
[]
21
string-without-aaa-or-bbb
[Java/Python 3] Two simple logic readable codes, iterative and recursive versions.
javapython-3-two-simple-logic-readable-c-9n47
If current result ends with aa, next char is b; if ends with bb, next char must be a.\n2. Other cases, if A > B, next char is a; otherwise, next char is b.\n\nj
rock
NORMAL
2019-01-27T04:22:33.940662+00:00
2022-02-07T15:53:34.618374+00:00
4,296
false
1. If current result ends with `aa`, next char is `b`; if ends with `bb`, next char must be `a`.\n2. Other cases, if A > B, next char is `a`; otherwise, next char is `b`.\n\n```java\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder(A + B);\n while (A + B > 0) {\n ...
77
1
[]
14
string-without-aaa-or-bbb
APPLES and BANANAS solution (with picture)
apples-and-bananas-solution-with-picture-h56u
Somehow... this weird but fun solution came about:\n\n1. Determine A or B is bigger. "Lay down" the more frequent character in a column of pairs, until we run o
lindyhop
NORMAL
2020-02-14T06:43:32.132023+00:00
2020-06-18T16:14:41.478406+00:00
2,830
false
Somehow... this weird but fun solution came about:\n\n1. Determine A or B is bigger. "Lay down" the more frequent character in a column of pairs, until we run out of the more frequent character.\n2. Row by row, we "top off" each pair of characters with the less frequent character, until we run out of the less frequent ...
74
1
[]
5
string-without-aaa-or-bbb
Clean C++/python solution
clean-cpython-solution-by-lbjlc-rjc1
C++:\n\nclass Solution {\npublic:\n string strWithout3a3b(int A, int B) {\n if(A == 0) return string(B, \'b\');\n else if(B == 0) return string
lbjlc
NORMAL
2019-01-27T04:33:45.076741+00:00
2019-01-27T04:33:45.076791+00:00
4,335
false
C++:\n```\nclass Solution {\npublic:\n string strWithout3a3b(int A, int B) {\n if(A == 0) return string(B, \'b\');\n else if(B == 0) return string(A, \'a\');\n else if(A == B) return "ab" + strWithout3a3b(A - 1, B - 1);\n else if(A > B) return "aab" + strWithout3a3b(A - 2, B - 1);\n ...
63
2
[]
9
string-without-aaa-or-bbb
Java straightforward
java-straightforward-by-wangzi6147-95dn
\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder();\n while(A + B > 0) {\n i
wangzi6147
NORMAL
2019-01-27T04:01:16.460881+00:00
2019-01-27T04:01:16.460928+00:00
2,929
false
```\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder();\n while(A + B > 0) {\n int l = sb.length();\n if (l > 1 && sb.charAt(l - 2) == sb.charAt(l - 1)) {\n if (sb.charAt(l - 1) == \'a\') {\n ...
35
2
[]
4
string-without-aaa-or-bbb
C++ short and simple solution
c-short-and-simple-solution-by-chrisys-u4y1
```\nstring strWithout3a3b(int A, int B) {\n std::string res;\n \n while (A && B) {\n if (A > B) {\n res += "aab"
chrisys
NORMAL
2019-01-27T14:05:36.027716+00:00
2019-01-27T14:05:36.027762+00:00
1,849
false
```\nstring strWithout3a3b(int A, int B) {\n std::string res;\n \n while (A && B) {\n if (A > B) {\n res += "aab";\n A--;\n } else if (B > A) {\n res += "bba";\n B--;\n } else {\n res += "ab"...
33
2
[]
2
string-without-aaa-or-bbb
my python solution without loop, beat 100%
my-python-solution-without-loop-beat-100-jb2k
\n\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n
wangyanpeng
NORMAL
2019-01-28T10:52:45.052790+00:00
2019-01-28T10:52:45.052832+00:00
1,145
false
\n```\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n if A >= 2*B:\n return \'aab\'* B + \'a\'* (A-2*B)\n elif A >= B:\n return \'aab\' * (A-B) + \'ab\' * (2*B - A)\n eli...
16
0
[]
2