question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
⌀
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
minimum-time-to-visit-a-cell-in-a-grid
CPP | BFS - shortest path + greedy
cpp-bfs-shortest-path-greedy-by-kena7-gbow
Code
kenA7
NORMAL
2025-02-09T09:09:58.820171+00:00
2025-02-09T09:09:58.820171+00:00
5
false
# Code ```cpp [] class Solution { public: #define vt vector<int> int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; bool valid(int i,int j, int m,int n) { if(i>=0 && j>=0 && i<m && j<n) return true; return false; } bool possible(int i,int j, int t, vector<vector<int>>...
0
0
['C++']
0
minimum-time-to-visit-a-cell-in-a-grid
Dijkstra's
dijkstras-by-akshaypatidar33-8onk
Code
akshaypatidar33
NORMAL
2025-02-06T09:42:37.759079+00:00
2025-02-06T09:42:37.759079+00:00
2
false
# Code ```cpp [] class Solution { public: int minimumTime(vector<vector<int>>& grid) { if(grid[0][0]>0 || (grid[0][1]>1 && grid[1][0]>1)) return -1; int n = grid.size(), m = grid[0].size(); vector<vector<int>> dist(n,vector<int>(m,INT_MAX)); priority_queue<pair<int, pair<int, int>>,...
0
0
['Breadth-First Search', 'Heap (Priority Queue)', 'Matrix', 'C++']
0
minimum-time-to-visit-a-cell-in-a-grid
Dijkstra’s Algorithm
dijkstras-algorithm-by-zozo_tm-zaaw
Code
zozo_tm
NORMAL
2025-01-25T02:17:51.924465+00:00
2025-01-25T02:17:51.924465+00:00
2
false
# Code ```python3 [] class Solution: def minimumTime(self, grid: List[List[int]]) -> int: # edge case if grid[0][1] > 1 and grid[1][0] > 1: return -1 # initialize m, n = len(grid), len(grid[0]) trans = [(0,1),(0,-1),(1,0),(-1,0)] INF = float('inf') ...
0
0
['Array', 'Heap (Priority Queue)', 'Python3']
0
minimum-time-to-visit-a-cell-in-a-grid
2577. Minimum Time to Visit a Cell In a Grid
2577-minimum-time-to-visit-a-cell-in-a-g-v1rl
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-19T03:51:53.829087+00:00
2025-01-19T03:51:53.829087+00:00
4
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
minimum-time-to-visit-a-cell-in-a-grid
Python (Simple Dijkstra's algorithm)
python-simple-dijkstras-algorithm-by-rno-o5ko
IntuitionApproachComplexity Time complexity: Space complexity: Code
rnotappl
NORMAL
2025-01-07T18:24:13.956911+00:00
2025-01-07T18:24:13.956911+00:00
4
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
minimum-time-to-visit-a-cell-in-a-grid
I hope you like it
i-hope-you-like-it-by-sajedkarimy-q9li
Let's say, I am just proud of myself 😅.First, note that if we can take the first move, we can reach the last cell too, as we can move back and fourth between th
sajedkarimy
NORMAL
2025-01-06T08:35:37.370863+00:00
2025-01-06T08:35:37.370863+00:00
5
false
Let's say, I am just proud of myself 😅. First, note that if we can take the first move, we can reach the last cell too, as we can move back and fourth between the first two cells till all the cells are open to enter. Moreover, assuming a cell is reachable via a path of valid cells (including the target as well), w...
0
0
['Python3']
0
minimum-time-to-visit-a-cell-in-a-grid
easiest bfs & dijkstra soln, java code.
easiest-bfs-dijkstra-soln-java-code-by-p-s5hb
Intuition & Approachcase1: when on start cell, we have two options to explore with, right or down, and time taken to reach them is 1s, but if their minTime > 1,
piyush_mehta22
NORMAL
2024-12-26T05:37:12.310608+00:00
2024-12-26T05:37:12.310608+00:00
6
false
# Intuition & Approach <!-- Describe your first thoughts on how to solve this problem. --> case1: when on start cell, we have two options to explore with, right or down, and time taken to reach them is 1s, but if their minTime > 1, we can't go anywhere, we stuck, we return -1 case2: when we stuck on some other cell, wh...
0
0
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'Java']
0
minimum-time-to-visit-a-cell-in-a-grid
C++ solution
c-solution-by-csld-cjw2
2577. Minimum Time to Visit a Cell In a GridSolutionGood day, let’s tease our brain.Understanding the problemThe problem asks us to find the minimum time requir
csld
NORMAL
2024-12-20T16:03:05.736330+00:00
2024-12-20T16:03:05.736330+00:00
7
false
# 2577. Minimum Time to Visit a Cell In a Grid ## Solution Good day, let’s tease our brain. ### Understanding the problem The problem asks us to find the minimum time required traversing from the top-left to the bottom-right, this implicitly implies the fact that we maybe using Dijkstra’s algorithm to solve this. ...
0
0
['C++']
0
minimum-time-to-visit-a-cell-in-a-grid
Dijkstra question in Google interview
dijkstra-question-in-google-interview-by-i27j
null
guohaoyu110
NORMAL
2024-12-11T06:58:13.442919+00:00
2024-12-11T06:58:13.442919+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\u8FD9\u4E2A\u89E3\u6CD5\u5E76\u6CA1\u6709\u771F\u7684\u201C\u9000\u56DE\u53BB\u201D\uFF0C\u800C\u662F\u901A\u8FC7\u539F\u5730\u7B49\u5F85\u6765\u6EE1\u8DB3\u65F6\u95F4\u7EA6\u675F\u3002 \n# Approach\n<!-- Describe your approach to solvin...
0
0
['Python3']
1
minimum-time-to-visit-a-cell-in-a-grid
Java solution.
java-solution-by-neelarunabh-najx
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
neelarunabh
NORMAL
2024-12-08T00:54:14.696005+00:00
2024-12-08T00:54:14.696030+00:00
2
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(m * n log(m * n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexi...
0
0
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'Java']
0
minimum-time-to-visit-a-cell-in-a-grid
C solution.
c-solution-by-neelarunabh-sr1z
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
neelarunabh
NORMAL
2024-12-08T00:50:57.422405+00:00
2024-12-08T00:50:57.422433+00:00
1
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(m * n log(m * n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m * n)\n<!-- Add your space comp...
0
0
['Array', 'Breadth-First Search', 'Graph', 'C', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path']
0
minimum-time-to-visit-a-cell-in-a-grid
C++ solution.
c-solution-by-neelarunabh-tvfc
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
neelarunabh
NORMAL
2024-12-08T00:37:26.400832+00:00
2024-12-08T00:37:26.400855+00:00
5
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(m * n log(m * n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m * n)\n<!-- Add your space comp...
0
0
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'C++']
0
two-best-non-overlapping-events
Very Simple sort + greedy: No DP, no Binary Search, no Heap/PQ/BST
very-simple-sort-greedy-no-dp-no-binary-2erca
Split events into separate start & end, keep track of best event that has ended so far.\n\n\n# super clean, no need for DP or BST.\nclass Solution:\n def max
elimsamazak1
NORMAL
2021-11-01T08:57:38.687898+00:00
2021-11-01T09:11:54.284740+00:00
7,688
false
Split events into separate start & end, keep track of best event that has ended so far.\n\n```\n# super clean, no need for DP or BST.\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n proc = []\n ans = m = 0 # m represents max value of finished event so far\n for s,e,...
123
0
[]
20
two-best-non-overlapping-events
100% Beats Simple Binary Search
100-beats-simple-binary-search-by-sumeet-ez91
Solution Explanation: Maximizing the Sum of Two Non-overlapping Events \uD83C\uDF1F\n\n## Intuition \uD83D\uDCA1\nThe problem asks us to select at most two non-
Sumeet_Sharma-1
NORMAL
2024-12-08T02:00:49.279663+00:00
2024-12-08T11:42:28.257163+00:00
25,252
false
# Solution Explanation: Maximizing the Sum of Two Non-overlapping Events \uD83C\uDF1F\n\n## Intuition \uD83D\uDCA1\nThe problem asks us to select at most two non-overlapping events such that the sum of their values is maximized. The key challenge is ensuring that the two selected events do not overlap. We need an appro...
117
0
['Binary Search', 'C', 'Sorting', 'C++', 'Java', 'Python3', 'Rust', 'Ruby', 'JavaScript', 'C#']
22
two-best-non-overlapping-events
C++ || Recursion + Memoization || Easy Understanding
c-recursion-memoization-easy-understandi-sugz
\n// Basically my intuition is sort of similar like Knapsack picking.\n// We have two options : Pick Event or Don\'t Pick an event.\n// If we "Pick event", we\'
simp_coder
NORMAL
2021-10-30T18:16:12.372473+00:00
2021-10-30T18:25:21.555093+00:00
5,612
false
```\n// Basically my intuition is sort of similar like Knapsack picking.\n// We have two options : Pick Event or Don\'t Pick an event.\n// If we "Pick event", we\'ll just add to our sum, then we\'ll find out an event whose starting time > ending time of the event that we picked and \n// we\'ll keep progressing like thi...
88
4
['Memoization', 'C', 'Binary Tree']
15
two-best-non-overlapping-events
C++ | with explanation | Concise | DP
c-with-explanation-concise-dp-by-aman282-tk2v
Idea:-\n1. Sort the events according to startTime and iterate from last.\n2. maxi will store maximum value from events whose startTime>= current event\'s startT
aman282571
NORMAL
2021-10-30T16:00:44.789961+00:00
2021-10-31T02:23:42.062437+00:00
8,730
false
**Idea:-**\n1. Sort the events according to ```startTime``` and iterate from last.\n2. ```maxi``` will store maximum value from events whose ```startTime>= current event\'s startTime```.\n3. So when we are iterating over events we check the map to find an event whose ```startTime``` is greater than current event\'s end...
81
3
['Dynamic Programming', 'C']
10
two-best-non-overlapping-events
Sort + Min Heap
sort-min-heap-by-votrubac-rilf
We sort events by the start date, and then go left to right. We also track end times and values in a min heap.\n\nWhen we process an event, we remove past event
votrubac
NORMAL
2021-10-30T17:46:06.317240+00:00
2021-10-30T17:56:13.588938+00:00
6,609
false
We sort events by the start date, and then go left to right. We also track end times and values in a min heap.\n\nWhen we process an event, we remove past events from the min heap, and track the `max_val` so far.\n\n**C++**\nPriority queue is a max heap by default; we can just store end times as negative instead of pro...
73
0
['C']
11
two-best-non-overlapping-events
Python: Actually simple with heap
python-actually-simple-with-heap-by-berg-50l0
So, notice that if we sort events, then we always have the left bound increasing. Therefore, we can keep a heap of (right_bound, value) tuples from events that
bergjak
NORMAL
2021-10-30T16:26:51.906560+00:00
2021-10-30T16:39:38.683659+00:00
2,285
false
So, notice that if we sort events, then we always have the left bound increasing. Therefore, we can keep a heap of (right_bound, value) tuples from events that we have seen so far. Whenever the current left bound becomes larger than the right_bound on the stack, that means we can start poppping from the heap to look fo...
38
1
[]
4
two-best-non-overlapping-events
Simple Java solution with explanation - Sort + Heap
simple-java-solution-with-explanation-so-19gr
This problem can be solved with the help of heap.\n\n- First sort all events by start time. If start time of two events are equal, sort them by end time.\n- The
divyagarg2601
NORMAL
2021-10-30T16:00:46.800283+00:00
2021-10-31T01:10:57.144542+00:00
2,499
false
This problem can be solved with the help of `heap`.\n\n- First sort all events by start time. If start time of two events are equal, sort them by end time.\n- Then take a priority queue that takes an array containing `[endtime, value]`. Priority queue will sort elements on the basis of `end time`.\n- Iterate through ev...
37
0
[]
9
two-best-non-overlapping-events
Sort+ Greedy vs DP+binary Search||22ms beats 100%
sort-greedy-vs-dpbinary-search22ms-beats-hzql
Intuition\n Describe your first thoughts on how to solve this problem. \nThe events[i] has the info (start[i], end[i], value[i]). How to distinguish between sta
anwendeng
NORMAL
2024-12-08T00:50:03.165912+00:00
2024-12-08T02:45:16.928130+00:00
6,378
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe events[i] has the info (start[i], end[i], value[i]). How to distinguish between `start` and `end` & to find a way keeping correct time ordering?\n\nConsider the info tuple `(time, isEnd, value)`; there are 2 tuples for 1 event. So bui...
33
0
['Binary Search', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Sorting', 'C++']
13
two-best-non-overlapping-events
C++ | Sorting + Priority Queue | DP+ Binary Search
c-sorting-priority-queue-dp-binary-searc-r47t
Solution 1: Sorting + Priority Queue\n\nSteps:\n1. First sort the events on basis of their starting time .\n2. We will use priority queue to store events that h
priyal04
NORMAL
2021-11-30T08:30:06.916848+00:00
2021-11-30T10:53:27.615697+00:00
2,320
false
### Solution 1: Sorting + Priority Queue\n\n**Steps:**\n1. First sort the events on basis of their starting time .\n2. We will use priority queue to store events that have started before the current event.\n3. Elements in priority queue are of type vector {minus of endTime , startTime , value} (ordered by endTime i.e e...
27
3
['Dynamic Programming', 'C', 'Sorting', 'Heap (Priority Queue)', 'Binary Tree']
4
two-best-non-overlapping-events
Java Sorting (10 liner)
java-sorting-10-liner-by-vikrant_pc-6xz5
\npublic int maxTwoEvents(int[][] events) {\n\tint result = 0, maxOfCompletedEvents = 0;\n\tArrays.sort(events, (x,y)->x[0]-y[0]); // Sort by Start time\n\tPr
vikrant_pc
NORMAL
2021-10-30T16:00:47.604661+00:00
2021-10-30T17:48:10.820709+00:00
1,734
false
```\npublic int maxTwoEvents(int[][] events) {\n\tint result = 0, maxOfCompletedEvents = 0;\n\tArrays.sort(events, (x,y)->x[0]-y[0]); // Sort by Start time\n\tPriorityQueue<int[]> inProgressQueue = new PriorityQueue<>((x,y)->x[1]-y[1]); // sorted by end time\n\tfor(int[] currentEvent : events) {\n\t\twhile(!inProgres...
21
3
[]
4
two-best-non-overlapping-events
Simple Solution with Priority Queue | ✅Beats 100% | C++ | Java | Python | JavaScript
simple-solution-with-priority-queue-beat-a2b9
\n\n# \u2B06\uFE0FUpvote if it helps \u2B06\uFE0F \n\n---\n\n## Connect with me on Linkedin Bijoy Sing. \n\n---\n\n\n## Follow me also on Codeforces: Bijoy Si
BijoySingh7
NORMAL
2024-12-08T05:28:07.941455+00:00
2024-12-08T17:39:47.146358+00:00
4,173
false
\n\n# \u2B06\uFE0FUpvote if it helps \u2B06\uFE0F \n\n---\n\n## Connect with me on Linkedin [Bijoy Sing](https://www.linkedin.com/in/bijoy-sing-236a5a1b2/). \n\n---\n\n\n## Follow me also on Codeforces: [Bijoy Sing](https://codeforces.com/profile/BijoySingh7) \n\n---\n\n\n###### *Solution in C++, Python, Java, and J...
20
0
['Array', 'Binary Search', 'Dynamic Programming', 'Sorting', 'Heap (Priority Queue)', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
9
two-best-non-overlapping-events
Python | Greedy & Binary Search
python-greedy-binary-search-by-khosiyat-8zru
see the Successfully Accepted Submission\n\n# Code\npython3 []\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n # Step 1:
Khosiyat
NORMAL
2024-12-08T03:13:44.919449+00:00
2024-12-08T03:13:44.919470+00:00
2,341
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/two-best-non-overlapping-events/submissions/1473126424/?envType=daily-question&envId=2024-12-08)\n\n# Code\n```python3 []\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n # Step 1: Sort the events based on the...
20
1
['Python3']
4
two-best-non-overlapping-events
Multiple Approaches | Heap Based || DP + Binary Search || C++ Clean Code
multiple-approaches-heap-based-dp-binary-u7og
Approach 1: Sorting + Priority Queue\n\nThis approach is best suited when we have just "at most 2" events to attend.\n\n# Code : \n\n\nint maxTwoEvents(vector<v
i_quasar
NORMAL
2021-11-18T02:19:19.489263+00:00
2021-11-19T16:59:53.429100+00:00
1,184
false
**Approach 1: Sorting + Priority Queue**\n\nThis approach is best suited when we have just **"at most 2"** events to attend.\n\n# Code : \n\n```\nint maxTwoEvents(vector<vector<int>>& events) {\n \n\tint n = events.size();\n\n\tpriority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; ...
19
0
['Dynamic Programming', 'Memoization', 'C', 'Heap (Priority Queue)', 'Binary Tree']
1
two-best-non-overlapping-events
JAVA || Sorting || PriorityQueue || O(NlogN)
java-sorting-priorityqueue-onlogn-by-chi-b9sb
This problem can be solved with the help of Sorting and Heap - \n\nFirst sort all events by start time. If start time of two events are equal, sort them by end
chirag_103
NORMAL
2022-05-11T07:48:37.261695+00:00
2022-05-11T07:48:37.261735+00:00
1,637
false
This problem can be solved with the help of Sorting and Heap - \n\nFirst sort all events by start time. If start time of two events are equal, sort them by end time.\nThen take a priority queue that takes an array containing [endtime, value]. Priority queue will sort elements on the basis of end time.\nIterate through ...
18
1
['Sorting', 'Heap (Priority Queue)', 'Java']
1
two-best-non-overlapping-events
[Python3] binary search
python3-binary-search-by-ye15-eran
\n\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n time = []\n vals = []\n ans = prefix = 0\n for st
ye15
NORMAL
2021-10-30T16:13:23.853976+00:00
2021-11-04T03:39:53.417061+00:00
1,954
false
\n```\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n time = []\n vals = []\n ans = prefix = 0\n for st, et, val in sorted(events, key=lambda x: x[1]): \n prefix = max(prefix, val)\n k = bisect_left(time, st)-1\n if k >= 0: val...
18
0
['Python3']
1
two-best-non-overlapping-events
📌📌 Heap || very-Easy || Well-Explained 🐍
heap-very-easy-well-explained-by-abhi9ra-hh78
IDEA:\nThis question is same as https://leetcode.com/problems/maximum-profit-in-job-scheduling/ .\n\n In this we have to consider atmost two events. So we will
abhi9Rai
NORMAL
2021-10-30T17:43:20.332694+00:00
2021-10-30T17:43:20.332733+00:00
1,519
false
## IDEA:\n**This question is same as https://leetcode.com/problems/maximum-profit-in-job-scheduling/ .**\n\n* In this we have to consider atmost two events. So we will only put the cureent profit in heap.\n\n* Maintain one variable res1 for storing the maximum value among all the events ending before the current event ...
17
2
['Heap (Priority Queue)', 'Python', 'Python3']
2
two-best-non-overlapping-events
Understanding the pattern | Java Solution | Recursion + Memoization
understanding-the-pattern-java-solution-ezq90
I wanted to solve binary search + dp problems and was looking for similar patterns.\nAfter few hours of grilling and understanding patterns between \nhttps://l
shadowpint
NORMAL
2022-08-24T22:50:23.614252+00:00
2022-08-24T22:50:23.614291+00:00
871
false
I wanted to solve binary search + dp problems and was looking for similar patterns.\nAfter few hours of grilling and understanding patterns between \nhttps://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/\nhttps://leetcode.com/problems/two-best-non-overlapping-events/\nhttps://leetcode.com/pro...
12
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Binary Tree', 'Java']
1
two-best-non-overlapping-events
C++ || O(NlogN) || DP + Binary Search || Priority Queue || Sorting
c-onlogn-dp-binary-search-priority-queue-pcdm
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n\n1.Sorting array on basis of start time to have sequential acces to all
abhay5349singh
NORMAL
2021-10-30T16:04:42.683614+00:00
2024-04-02T04:05:42.252109+00:00
1,451
false
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n\n1.Sorting array on basis of start time to have sequential acces to all events.\n2.Each event can be attended in 2 ways: `single` or `pair-up with max profitable non conflicting event`\n\n```\nclass Solution {\npublic:\n ...
12
0
['Dynamic Programming', 'Sorting', 'Binary Tree', 'C++']
4
two-best-non-overlapping-events
Simple Java Solution - With Comments (Left Max + Right Max)
simple-java-solution-with-comments-left-030zo
\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // for any timestamp - find max of values to left and max of values to right\n\n
pavankumarchaitanya
NORMAL
2021-10-30T16:02:24.776290+00:00
2021-10-30T16:02:39.145186+00:00
1,009
false
```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // for any timestamp - find max of values to left and max of values to right\n\n Arrays.sort(events, (a,b)->a[1]-b[1]);// Sort by end time - to know what events happened previously\n TreeMap<Integer, Integer> maxSeenMapOnLeft = ...
12
4
[]
2
two-best-non-overlapping-events
🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏
beats-super-easy-beginners-by-codewithsp-j06r
\n\n## MOST IMP POINT\n### At most two non-overlapping \n\n\n\n\n\n\n---\nHere\u2019s the detailed breakdown of the problem-solving process for maximizing the
CodeWithSparsh
NORMAL
2024-12-08T09:12:06.753205+00:00
2024-12-08T12:44:35.147931+00:00
1,043
false
![image.png](https://assets.leetcode.com/users/images/df80087f-7ffc-48c1-94a0-185718d3923b_1733648929.941429.png)\n\n## MOST IMP POINT\n### At most two non-overlapping \n\n![1000028386.png](https://assets.leetcode.com/users/images/3efa41c6-e350-4e3c-b9c9-189456a98878_1733661169.9060109.png)\n\n\n\n\n---\nHere\u2019s t...
11
0
['Array', 'Binary Search', 'C', 'Sorting', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'Dart']
2
two-best-non-overlapping-events
Easy Solution | O(nlogn) | Priority Queue | Maximum Sum
easy-solution-onlogn-priority-queue-maxi-vqjf
Intuition\n Describe your first thoughts on how to solve this problem. \nThe key idea is to sort the events by their start times and use a priority queue to tra
Sachin6763
NORMAL
2024-12-08T03:32:45.223661+00:00
2024-12-08T03:32:45.223684+00:00
2,592
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key idea is to sort the events by their start times and use a priority queue to track the maximum value of events that end before the current event\'s start time. This allows us to efficiently determine the best event to pair with the...
10
0
['C', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Java', 'Python3']
5
two-best-non-overlapping-events
Python 3 || 11 lines, 2ptrs || T/S: 90% / 26%
python-3-11-lines-2ptrs-ts-90-26-by-spau-1fhp
Here\'s the plan:\n\n1. We unzip events, rezip vals with each beg and end, and then sort each of these lists.\n\n1. We iterate through the lists similtaneously
Spaulding_
NORMAL
2024-04-07T00:41:27.710270+00:00
2024-06-11T22:31:57.791284+00:00
594
false
Here\'s the plan:\n\n1. We unzip `events`, rezip `vals` with each `beg` and `end`, and then sort each of these lists.\n\n1. We iterate through the lists similtaneously keeping track of the max value of all the events to the left and determining the value immediately to the right; if the sum of the left max value and th...
9
0
['Python3']
0
two-best-non-overlapping-events
✅C++ || Recursion->Memoization->Tabulation || 01-Knapsack
c-recursion-memoization-tabulation-01-kn-rgdi
Method - 1 [Recursion]\n\n\nT->O(Expo) && S->O(n) [Recursion stack space]\n\nclass Solution {\npublic:\n int f(int i,int count,vector& st,vector>& eve,int n)
abhinav_0107
NORMAL
2022-10-01T12:57:35.236364+00:00
2022-10-01T12:57:35.236405+00:00
918
false
# Method - 1 [Recursion]\n![image](https://assets.leetcode.com/users/images/f4931dd3-0490-45f9-b03d-477b5e9d4210_1664628217.7387586.png)\n\n**T->O(Expo) && S->O(n) [Recursion stack space]**\n\nclass Solution {\npublic:\n int f(int i,int count,vector<int>& st,vector<vector<int>>& eve,int n){\n if(i>=n || count...
8
0
['Binary Search', 'Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']
1
two-best-non-overlapping-events
Java Concise with Explanation
java-concise-with-explanation-by-adaltio-emxf
\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // -sort the events by start time\n // -rely on the fact that for any event ev
AdAltioraTendo
NORMAL
2022-01-04T21:55:32.815731+00:00
2022-01-04T21:55:32.815759+00:00
442
false
```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // -sort the events by start time\n // -rely on the fact that for any event events[i], all events after events[i] start at a time\n // after events[i] and so do not overlap with any previous events not overlapping with events[i]...
8
0
['Heap (Priority Queue)', 'Java']
0
two-best-non-overlapping-events
EASY TO MEDIUM C++ SOLUTION SOLVED || 2054. Two Best Non-Overlapping Events
easy-to-medium-c-solution-solved-2054-tw-v7xn
Intuition\n\nThe goal is to find the maximum value of two non-overlapping events from a list of events, where each event has a start time, end time, and value.
shivambit
NORMAL
2024-12-08T09:16:17.175190+00:00
2024-12-08T09:16:17.175217+00:00
471
false
# Intuition\n\nThe goal is to find the maximum value of two non-overlapping events from a list of events, where each event has a start time, end time, and value. The optimal approach involves sorting the events by their start times and leveraging a priority queue to track the maximum value of events that end before the...
7
0
['Array', 'Sorting', 'Heap (Priority Queue)', 'C++']
0
two-best-non-overlapping-events
✅ One Line Solution
one-line-solution-by-mikposp-k37h
Binary Search + Right Max \n(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - Three
MikPosp
NORMAL
2023-10-19T10:45:13.572403+00:00
2024-12-08T10:17:04.499840+00:00
594
false
<!--Binary Search + Right Max-->\n(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - Three Lines\nTime complexity: $$O(n*log(n))$$. Space complexity: $$O(n)$$.\n```python3\nclass Solution:\n def maxTwoEvents(self, a: List[List[int]]) -> int:\...
7
1
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'Python', 'Python3']
0
two-best-non-overlapping-events
Complete Detailed Explanation || Most Intuitive Linear DP + Binary Search Solution || C++ ||
complete-detailed-explanation-most-intui-4qdc
Intuition\nFirst Thing WE can understand from the problem is to sort the events first for getting non-overlapping two events. \nThen we can calculate the upperb
brucewayne_5
NORMAL
2023-07-15T12:05:59.981628+00:00
2023-07-15T12:05:59.981646+00:00
591
false
# Intuition\nFirst Thing WE can understand from the problem is to sort the events first for getting **non-overlapping** two events. \nThen we can calculate the upperbound for current event ending time for choosing next event.\n\n# Approach\nAs mentioned in the intuition we first sort the array.\nThen Here we can observ...
7
0
['Binary Search', 'Dynamic Programming', 'C++']
0
two-best-non-overlapping-events
C++| 97% faster | 99.26% memory | Binary Search | Explained
c-97-faster-9926-memory-binary-search-ex-4kpy
Steps are explained in comments (If any doubt or any modification please comment)\n\n\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& even
Priyansh_34
NORMAL
2021-11-06T20:12:40.958958+00:00
2021-11-06T20:16:03.335171+00:00
626
false
**Steps are explained in comments** (If any doubt or any modification please comment)\n\n```\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n ios::sync_with_stdio(false);cin.tie(NULL);\n \n //sort the events according to their start time\n sort(events.begin()...
7
0
['Binary Tree']
2
two-best-non-overlapping-events
C++ | Brute force to Binary Search | TC->O(nlogn),SC->O(n) |Commented
c-brute-force-to-binary-search-tc-onlogn-eub4
\n//Brute Force\nYou must have to undernstand brute force ,if you want to fully get the observation of my binary search solution.\noptimize one will become very
lazy_buddy
NORMAL
2021-10-31T09:42:53.745270+00:00
2021-10-31T13:38:33.802640+00:00
344
false
```\n//Brute Force\nYou must have to undernstand brute force ,if you want to fully get the observation of my binary search solution.\noptimize one will become very easy ,so get idea about brute fce and jump to optimized one.\n\nint maxTwoEvents(vector<vector<int>>&a) {\n \n int n=a.size();\n int re...
6
1
['Array', 'Sorting', 'Binary Tree']
0
two-best-non-overlapping-events
Binary Search Approach ✅✅
binary-search-approach-by-arunk_leetcode-xnpr
Intuition\nTo solve this problem, we need to select at most two non-overlapping events to maximize the total value. Sorting the events by start time simplifies
arunk_leetcode
NORMAL
2024-12-08T16:02:27.759898+00:00
2024-12-08T16:03:41.730204+00:00
487
false
# Intuition\nTo solve this problem, we need to select at most two non-overlapping events to maximize the total value. Sorting the events by start time simplifies the problem, allowing efficient checks for overlaps and the use of binary search to find valid second events.\n\n# Approach\n1. **Sort Events**: First, sort t...
5
0
['Binary Search', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'Python ML']
1
two-best-non-overlapping-events
Solution for waifujahat | C# | 100% Both using Binary Search
solution-for-waifujahat-c-100-both-using-qtky
\n\n---\n\n# How to solve\nThe goal of this task is to find the maximum sum of values by selecting at most two non-overlapping events, I need to ensure the two
waifujahat
NORMAL
2024-12-08T03:33:15.125103+00:00
2024-12-08T13:50:30.437727+00:00
212
false
![Screenshot 2024-12-08 102114.png](https://assets.leetcode.com/users/images/a7b8414f-b60a-400c-8b9b-3aab58b971cb_1733628097.4585931.png)\n\n---\n\n# How to solve\nThe goal of this task is to find the maximum sum of values by selecting at most two non-overlapping events, I need to ensure the two chosen events don\'t ov...
5
0
['Array', 'Binary Search', 'Dynamic Programming', 'Sorting', 'Heap (Priority Queue)', 'C#']
1
two-best-non-overlapping-events
c++ | Memoization+Binary Search | Explaination
c-memoizationbinary-search-explaination-6tkyj
Solution-Memoization + Binary Search\n\nThought Process\n1. For every event, I\'ve two options. Whether I choose that event or not.\n2. If choose, then I add it
ritvikmahajan17
NORMAL
2021-11-23T07:09:46.689710+00:00
2021-11-23T07:12:21.649213+00:00
372
false
# Solution-Memoization + Binary Search\n\n*Thought Process*\n1. For every event, I\'ve two options. Whether I choose that event or not.\n2. If choose, then I add its value to my answer. If not choosen I move forward to the next event.\n3. Now if I select a event, my next event has to have `start time > end time of choo...
5
0
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree']
0
two-best-non-overlapping-events
Java O(nlogn) Binary Search + Maximum Caching
java-onlogn-binary-search-maximum-cachin-7f3z
We only need to find a pair of non-overlapping events. Therefore, given one fixed event, we need to find the other event with non-overlapping to form a pair. Fo
gumingdiaoyu
NORMAL
2021-10-30T16:15:34.428005+00:00
2021-10-30T16:45:10.376080+00:00
601
false
We only need to find a pair of non-overlapping events. Therefore, given one fixed event, we need to find the other event with non-overlapping to form a pair. For each pair, we calculate the maximum. However, the complexity will be O(n^2).\n\nTo reduce the complexity, we use binary search to find the other event without...
5
0
['Sorting', 'Binary Tree', 'Java']
2
two-best-non-overlapping-events
[Python]: Binary Search + DP
python-binary-search-dp-by-sanathbhargav-n2kk
\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n def binarySearch(low, high, key):\n if low <= high:\n
sanathbhargav26
NORMAL
2021-10-30T16:11:27.474358+00:00
2021-10-30T16:11:27.474390+00:00
617
false
```\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n def binarySearch(low, high, key):\n if low <= high:\n mid = (low+high)//2\n if events[mid][1] >= key:\n return binarySearch(low, mid-1, key)\n else:\n ...
5
0
['Dynamic Programming', 'Binary Tree', 'Python']
0
two-best-non-overlapping-events
C++ Dynamic Programming
c-dynamic-programming-by-angold4-szjt
Starting from first day, each day has three possible works in this problem:\n\n1. End the first event (Case 1)\n2. Start the second event (Case 2)\n3. Do nothin
angold4
NORMAL
2021-10-30T18:21:02.404974+00:00
2021-10-31T05:28:06.852719+00:00
354
false
**Starting from first day, each day has three possible works in this problem:**\n\n1. **End the first event** (Case 1)\n2. **Start the second event** (Case 2)\n3. **Do nothing (or in event)** (Case 3)\n\n\n**And their relationship:**\n\n1. **`firstEnd = iValEnd`** (Case 1)\n2. **`secondBegin = max(old_firstEnd + iValBe...
4
0
[]
2
two-best-non-overlapping-events
Easy-understood Java solution with sort and postfix array
easy-understood-java-solution-with-sort-xa540
sort the events by the starting time\n2. create a postfix array to record the largest value after current starting time events[i][0]\n3. use binary search to fi
magi003769
NORMAL
2021-10-30T16:19:14.935487+00:00
2021-10-30T16:19:14.935521+00:00
565
false
1. sort the events by the starting time\n2. create a postfix array to record the largest value after current starting time `events[i][0]`\n3. use binary search to find the first event that starting later than the one at current iteration \n\n```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n ...
4
0
['Binary Search Tree', 'Sorting', 'Java']
0
two-best-non-overlapping-events
C Solution - Heap
c-solution-heap-by-jafwe-4jqt
c []\nvoid push(int **heap, int *new, int top)\n{\n heap[top] = new;\n int now = top;\n int *temp;\n int next = (top - 1) / 2;\n while (top)\n {\n if (
jafwe
NORMAL
2024-12-08T08:28:27.907494+00:00
2024-12-08T08:28:27.907522+00:00
62
false
```c []\nvoid push(int **heap, int *new, int top)\n{\n heap[top] = new;\n int now = top;\n int *temp;\n int next = (top - 1) / 2;\n while (top)\n {\n if (heap[now][2] > heap[next][2])\n {\n temp = heap[next];\n heap[next] = heap[now];\n heap[now] = temp;\n now = next;\n next = (now ...
3
0
['C']
0
two-best-non-overlapping-events
Two Best Non-overlapping Events - Easy Solution - 🌟 Nice Explanation 🌟
two-best-non-overlapping-events-easy-sol-yxkl
Intuition\n\n1. Sort the 2-D array events with respect to the start_time so we can compare the end time of previous element in the array with the elements in ot
RAJESWARI_P
NORMAL
2024-12-08T06:54:08.119632+00:00
2024-12-08T06:54:08.119666+00:00
219
false
# Intuition\n\n1. Sort the 2-D array events with respect to the start_time so we can compare the end time of previous element in the array with the elements in other index greater than the previous index.\n\n1. Use suffixMax to calculate the maximum value that can be obtained at each index.\n<!-- Describe your first th...
3
0
['Array', 'Binary Search', 'Sorting', 'Java']
0
two-best-non-overlapping-events
C++ | Binary Search
c-binary-search-by-ahmedsayed1-3e2d
Explaining\nfor each index i binary search on the first index greater than i that have start time greater than end time of i\n\n# Complexity\nO(n * log)\n\n# Co
AhmedSayed1
NORMAL
2024-12-08T04:59:27.494811+00:00
2024-12-08T07:02:03.300061+00:00
452
false
# Explaining\n<h3>for each index i binary search on the first index greater than i that have start time greater than end time of i</h3>\n\n# Complexity\n<h3>O(n * log)</h3>\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& x) {\n sort(x.begin(), x.end());\n\n int n...
3
0
['Binary Search', 'Sorting', 'C++']
1
two-best-non-overlapping-events
✅ Easy to Understand | Intuitive Approach with Binary Search with going Greedy | Detailed Video 🔥
easy-to-understand-intuitive-approach-wi-7bfp
Intuition\nThe problem involves finding the maximum value by selecting one or two non-overlapping events. The key is to leverage the sorted order of events and
sahilpcs
NORMAL
2024-12-08T03:53:17.118065+00:00
2024-12-08T03:53:17.118103+00:00
716
false
# Intuition\nThe problem involves finding the maximum value by selecting one or two non-overlapping events. The key is to leverage the sorted order of events and use an auxiliary array to quickly access the maximum possible value for subsequent events. This helps efficiently calculate the maximum value by combining two...
3
0
['Array', 'Binary Search', 'Sorting', 'Java']
2
two-best-non-overlapping-events
Simplified Sorting Solution without heaps / binary search - beats 96%
simplified-sorting-solution-without-heap-espc
Intuition\n- Brute Force: Sorting + double nested for loop to find the maximum interval before the current one that gives the maximum value.\n- Heap: Sort by st
lecoqif
NORMAL
2024-12-08T01:19:55.692183+00:00
2024-12-08T18:15:58.072410+00:00
163
false
# Intuition\n- Brute Force: Sorting + double nested for loop to find the maximum interval before the current one that gives the maximum value.\n- Heap: Sort by starts and ends, and add all intervals from ends into heap which are less than the current start. \n- Constant to keep track of max: Replace heap with a variabl...
3
0
['Python3']
0
two-best-non-overlapping-events
(1) Optimized Greedy in Array, (2) Max HeapQueue with Explanation
1-optimized-greedy-in-array-2-max-heapqu-1v8r
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nGreedy in Array.\n\n# Complexity\n- Time complexity: O(n * log n)\n Add y
stalebii
NORMAL
2024-12-08T00:45:32.905280+00:00
2024-12-08T01:22:15.307261+00:00
259
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nGreedy in Array.\n\n# Complexity\n- Time complexity: O(n * log 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(n)$$ -->\n\n# Code\n```pytho...
3
0
['Array', 'Binary Search', 'Dynamic Programming', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Python', 'Python3']
0
two-best-non-overlapping-events
Greedy Approach
greedy-approach-by-shivamsingh00141-wyq7
Intuition\nThe best way to choose an interval works as follows:\n\n-> choose any interval\n-> sum the value of chose events with the maximum value of events whi
shivamsingh00141
NORMAL
2023-10-24T18:02:03.565477+00:00
2023-10-24T18:02:03.565496+00:00
158
false
# Intuition\nThe best way to choose an interval works as follows:\n\n-> choose any interval\n-> sum the value of chose events with the maximum value of events which ended before it \n-> Now the maximum of the value we obtained in the above step is the answer\n\n# Complexity\n- Time complexity:\nO(nlog(n))\n\n- Space co...
3
0
['Greedy', 'C++']
0
two-best-non-overlapping-events
Python minheap solution | Leetcode 1477
python-minheap-solution-leetcode-1477-by-u0hq
\ndef maxTwoEvents(self, events: List[List[int]]) -> int:\n\tq, cur, ans = [], 0, 0\n\tfor s, e, v in sorted(events):\n\t\twhile(q and q[0][0]<s):\n\t\t\tcur =
vincent_great
NORMAL
2022-10-12T05:27:25.910573+00:00
2022-10-13T07:34:40.148709+00:00
191
false
```\ndef maxTwoEvents(self, events: List[List[int]]) -> int:\n\tq, cur, ans = [], 0, 0\n\tfor s, e, v in sorted(events):\n\t\twhile(q and q[0][0]<s):\n\t\t\tcur = max(cur, heappop(q)[1])\n\t\tans = max(ans, cur+v)\n\t\theappush(q, (e, v))\n\treturn ans\n```\nSimilar problem:\n[1477. Find Two Non-overlapping Sub-arrays ...
3
0
[]
0
two-best-non-overlapping-events
C++ || Min Heap
c-min-heap-by-narayan1281-ntl5
\nclass Solution {\npublic:\n \n int maxTwoEvents(vector<vector<int>>& events) {\n int n = events.size();\n priority_queue<pair<int,int>,vec
narayan1281
NORMAL
2022-09-18T11:43:02.887399+00:00
2022-09-18T11:43:02.887437+00:00
289
false
```\nclass Solution {\npublic:\n \n int maxTwoEvents(vector<vector<int>>& events) {\n int n = events.size();\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n // priority queue minheap --> to store endtime and values of the events\n sort(events.begin(),...
3
0
[]
1
two-best-non-overlapping-events
C++ Memoization code using simple upper bound function || Easy-Understanding
c-memoization-code-using-simple-upper-bo-62vo
\nint dp[100005][3];\n vector<int> vec;\n \n int func( vector<vector<int>> &events , int i , int choose , int n)\n {\n if(i==n)\n {\n
KR_SK_01_In
NORMAL
2022-03-25T15:04:54.471538+00:00
2022-03-25T15:05:33.657650+00:00
295
false
```\nint dp[100005][3];\n vector<int> vec;\n \n int func( vector<vector<int>> &events , int i , int choose , int n)\n {\n if(i==n)\n {\n return 0;\n }\n \n if(choose>=2)\n {\n return 0;\n }\n \n if(dp[i][choose]!=-1)\n ...
3
0
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree', 'C++']
0
two-best-non-overlapping-events
Explained C++ Min-heap Solution
explained-c-min-heap-solution-by-bishalp-dduy
Sort all the intervals in the events vector based on start time. The reason to sort this using start time will help when we check whether my current interval is
bishalpandit
NORMAL
2021-11-03T08:49:23.100216+00:00
2021-11-03T08:49:23.100243+00:00
313
false
1. Sort all the intervals in the events vector based on start time. The reason to sort this using start time will help when we check whether my current interval is non-overlapping with the interval at the top of min-heap(priority queue).\n\n2. You have to maintain a `min-heap` which will make sure you can have the int...
3
0
['Sorting', 'Heap (Priority Queue)']
0
two-best-non-overlapping-events
[Python] Heap for (end, val) | O(NlogN)
python-heap-for-end-val-onlogn-by-rpashu-ku93
O(NlogN) | O(N)\n1. Sort by start time\n2. Clean all elements from the heap with end < start and keep max V as res1\n3. Calculate max sum for at most two as res
rpashuto
NORMAL
2021-10-30T16:45:07.513923+00:00
2021-10-30T16:51:13.465232+00:00
2,379
false
O(NlogN) | O(N)\n1. Sort by start time\n2. Clean all elements from the heap with end < start and keep max V as res1\n3. Calculate max sum for at most two as res2, where res1 is largest v with end < current start\n3. Populate the heap at each event with (end, val) to consider it later, after we\'ll reach first start > t...
3
1
[]
0
two-best-non-overlapping-events
c++ solution using binary search not stl
c-solution-using-binary-search-not-stl-b-46oj
\nclass Solution {\npublic:\n static bool cmp(vector<int>&v1,vector<int>&v2)\n {\n return v1[1]<v2[1];\n }\n int maxTwoEvents(vector<vector<i
dilipsuthar17
NORMAL
2021-10-30T16:02:53.913301+00:00
2021-10-31T09:37:33.504204+00:00
405
false
```\nclass Solution {\npublic:\n static bool cmp(vector<int>&v1,vector<int>&v2)\n {\n return v1[1]<v2[1];\n }\n int maxTwoEvents(vector<vector<int>>&nums) \n {\n int n=nums.size();\n // vector<int>dp(n+10,0);\n sort(nums.begin(),nums.end(),cmp);\n // dp[0]=nums[0][2];\n...
3
0
['C', 'Binary Tree', 'C++']
2
two-best-non-overlapping-events
[ C++ | Java | Kotlin ] Simple binary search solution, detailed explanation, beats 100% 🚀
c-java-kotlin-simple-binary-search-solut-uv82
Intuition\nThe key insight is that since we can only select up to two non-overlapping events, we can:\n1. First sort the events by start time to make it easier
DmitryNekrasov
NORMAL
2024-12-08T15:18:55.826457+00:00
2024-12-08T15:31:48.616928+00:00
67
false
# Intuition\nThe key insight is that since we can only select up to two non-overlapping events, we can:\n1. First sort the events by start time to make it easier to find non-overlapping pairs\n2. For each event, try to pair it with the best possible non-overlapping event that comes after it\n3. Use preprocessing to qui...
2
0
['Array', 'Binary Search', 'Sorting', 'C++', 'Java', 'Kotlin']
1
two-best-non-overlapping-events
Simple Binary search solution
simple-binary-search-solution-by-pranavj-8ft4
Maximum Sum of Two Non-Overlapping Events\n\n## Problem Description\nGiven an array of events where each event is represented as a triplet \([s, e, v]\): \n- \
pranavjarande
NORMAL
2024-12-08T12:34:12.430616+00:00
2024-12-08T12:34:12.430656+00:00
23
false
# Maximum Sum of Two Non-Overlapping Events\n\n## Problem Description\nGiven an array of events where each event is represented as a triplet \\([s, e, v]\\): \n- \\(s\\): Start time of the event. \n- \\(e\\): End time of the event. \n- \\(v\\): Value of the event. \n\nThe goal is to find the **maximum sum of values...
2
0
['Binary Search', 'Prefix Sum', 'C++']
0
two-best-non-overlapping-events
✅ [Python] - Quick and Easy
python-quick-and-easy-by-danielol-oott
\n# Code\npython3 []\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n \n # Sort events by end time\n events.
DanielOL
NORMAL
2024-12-08T11:41:13.561709+00:00
2024-12-08T11:41:13.561748+00:00
110
false
\n# Code\n```python3 []\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n \n # Sort events by end time\n events.sort(key=lambda x: x[1])\n\n # Store maximum value of events seen so far\n max_value = 0\n result = 0\n\n # Create a list to stor...
2
0
['Array', 'Binary Search', 'Dynamic Programming', 'Sorting', 'Heap (Priority Queue)', 'Python3']
2
two-best-non-overlapping-events
Python DP Binary Search 3 lines
python-dp-binary-search-3-lines-by-sonng-iy65
Intuition\n Describe your first thoughts on how to solve this problem. \n- loop each event\n- val of this event + M := max(all event that have end < this_event.
sonnguyen2201
NORMAL
2024-12-08T09:08:57.628480+00:00
2024-12-08T09:29:07.232754+00:00
131
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- loop each event\n- val of this event + M := max(all event that have end < this_event.start)\n- How to find M?\n - Generate array EV = [[e0,v0],[e1,v1],....[elast,vlast]]\n - we binary search this_event.start in this array EV to fi...
2
0
['Python3']
0
two-best-non-overlapping-events
2054. Two Best Non-Overlapping Events
2054-two-best-non-overlapping-events-by-bvdac
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
AdilShamim8
NORMAL
2024-12-08T07:47:56.974691+00:00
2024-12-08T07:47:56.974714+00:00
60
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Python3']
0
two-best-non-overlapping-events
Pre Computation + Binary Search || O(n log n) || time better than 93.92% & space 88%
pre-computation-binary-search-on-log-n-t-53kr
\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n Arrays.sort(events,(a,b)->a[0]-b[0]);\n int ans=0;\n int n=events.lengt
Syed_Anwar_leetcode
NORMAL
2024-12-08T06:59:55.680220+00:00
2024-12-08T06:59:55.680255+00:00
139
false
```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n Arrays.sort(events,(a,b)->a[0]-b[0]);\n int ans=0;\n int n=events.length;\n int[] maxVal=new int[n];\n maxVal[n-1]=events[n-1][2];\n for(int i=n-2;i>=0;i--)\n maxVal[i]=Math.max(maxVal[i+1],events...
2
0
['Binary Search', 'Java']
0
two-best-non-overlapping-events
sort and use priority queue
sort-and-use-priority-queue-by-yanandsin-co0y
\n\nEvents (Sorted) ---> [Start, End, Value]\n\n Time Axis -->\nEvent 1: |------|\nEvent 2: |-------|\nEvent 3: |----|\n\nHeap --->
yanandsingh1411
NORMAL
2024-12-08T05:13:45.249329+00:00
2024-12-08T05:13:45.249356+00:00
298
false
\n```\nEvents (Sorted) ---> [Start, End, Value]\n\n Time Axis -->\nEvent 1: |------|\nEvent 2: |-------|\nEvent 3: |----|\n\nHeap ---> Keeps Events Active\n --------------\n | Event End |\n | Max Value |\n --------------\n\nmax_so_far ---> Tracks maximum value from non-overlap...
2
0
['Two Pointers', 'Greedy', 'Sliding Window', 'Sorting', 'Heap (Priority Queue)', 'Merge Sort', 'C++']
0
two-best-non-overlapping-events
Let come up with idea | Share thought
let-come-up-with-idea-share-thought-by-v-3udo
Intuition\n Describe your first thoughts on how to solve this problem. \nYou maybe easily find many solutions, it is not neccessary to share another solution he
vyhv
NORMAL
2024-12-08T04:56:58.683579+00:00
2024-12-08T04:56:58.683604+00:00
78
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou maybe easily find many solutions, it is not neccessary to share another solution here but I want to share my thought how can I come up to final problem. I hope I can help you.\n\nLet start...\n\nFirstly, I think this problem must to b...
2
0
['Binary Search', 'Dynamic Programming', 'Segment Tree', 'Sorting', 'Prefix Sum', 'C++']
0
two-best-non-overlapping-events
Simple Solution With Added Comments | Binary Search | Sorting | Time Complexity O(nlogn) |
simple-solution-with-added-comments-bina-301u
Intuition\nThe solution aims to maximize the sum of values from two non-overlapping events. Events are sorted by start time for efficient binary search. A right
nvdpsaluja
NORMAL
2024-12-08T03:53:45.312952+00:00
2024-12-08T03:53:45.312981+00:00
11
false
# Intuition\nThe solution aims to maximize the sum of values from two non-overlapping events. Events are sorted by start time for efficient binary search. A right-max array (`rmax`) stores the maximum value of events to the right. For each event, binary search finds the next non-overlapping event, and their values are ...
2
0
['C++']
0
two-best-non-overlapping-events
Simple Line Sweep Algorithm
simple-line-sweep-algorithm-by-up41guy-2xeu
More Line Sweep Problems:\nhttps://leetcode.com/problem-list/a0l633d6/\nhttps://leetcode.com/problem-list/a06u4275/\n\nhttps://carefree-ladka.github.io/js.enigm
Cx1z0
NORMAL
2024-12-08T03:10:57.206268+00:00
2024-12-08T15:35:57.225063+00:00
170
false
More **Line Sweep** Problems:\nhttps://leetcode.com/problem-list/a0l633d6/\nhttps://leetcode.com/problem-list/a06u4275/\n\nhttps://carefree-ladka.github.io/js.enigma/docs/tutorial-basics/LineSweep\n\n**Intuition:**\n - Take a list with start and end points \n - [start, 1, value] & [end, -1, val] Here 1 means starting a...
2
0
['Array', 'Line Sweep', 'Sorting', 'JavaScript']
1
two-best-non-overlapping-events
Kotlin || Binary Search
kotlin-binary-search-by-nazmulcuet11-kq8e
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
nazmulcuet11
NORMAL
2024-12-08T02:33:40.914468+00:00
2024-12-08T02:33:40.914499+00:00
61
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Binary Search', 'Kotlin']
0
two-best-non-overlapping-events
Two Pointer w/ on-the-fly prefix sums. 100%
two-pointer-w-on-the-fly-prefix-sums-100-0una
Intuition\nBecause we can only pick two events, first simply the problem to finding a second event which maximizes the value when added to a prefix sum. \n\n# A
conorpo
NORMAL
2024-12-08T01:24:32.528312+00:00
2024-12-08T01:24:32.528333+00:00
31
false
# Intuition\nBecause we can only pick two events, first simply the problem to finding a **second** event which maximizes the value when added to a prefix sum. \n\n# Approach\n- Split events into starts and ends, cloning the value. \n- Sort the vectors.\n- Go left to right on the start list, for each second event cantid...
2
0
['Rust']
0
two-best-non-overlapping-events
[JavaScript] 2054. Two Best Non-Overlapping Events
javascript-2054-two-best-non-overlapping-k0wh
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\nPrevious approach\n\n\n1 only 2 event values needed\n2 their sum must b
pgmreddy
NORMAL
2023-10-23T16:15:10.533138+00:00
2024-12-08T14:37:13.645849+00:00
120
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\nPrevious approach\n\n```\n1 only 2 event values needed\n2 their sum must be max\n3 the events must be non-overlapping ( seperate )\n\nsort events by end times\nmaxsum = 0\nfor each event (start, end, value)\n find an ev...
2
0
['JavaScript']
1
two-best-non-overlapping-events
Java PriorityQueue solution
java-priorityqueue-solution-by-kantariya-k4kp
\n# Code\n\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n int res = 0, maxVal = 0;\n //Min heap by ending time\n Priori
kantariyaraj
NORMAL
2023-02-07T09:33:26.773634+00:00
2023-02-07T09:33:26.773675+00:00
274
false
\n# Code\n```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n int res = 0, maxVal = 0;\n //Min heap by ending time\n PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));\n //Sort the array by start time\n Arrays.sort(events, Comparator....
2
0
['Java']
1
two-best-non-overlapping-events
easy to understand
easy-to-understand-by-vishwaneet_mishra-9go5
```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n int dp[][] = new int[events.length][3],output = 0;\n for(int row[]:dp) Arra
Vishwaneet_Mishra
NORMAL
2023-02-06T02:17:12.955560+00:00
2023-02-06T02:17:12.955589+00:00
305
false
```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n int dp[][] = new int[events.length][3],output = 0;\n for(int row[]:dp) Arrays.fill(row,-1);\n Arrays.sort(events,(a,b)->(a[0]-b[0]));\n int out = find(dp,events,0,2);\n for(int row[]:events) output = Math.max(outp...
2
0
['Dynamic Programming', 'Binary Tree', 'Java']
0
two-best-non-overlapping-events
Golang solution
golang-solution-by-derekmu-ch2a
Intuition\n\nConsider each event ordered by start time while keeping track of the largest already completed event in a copy of the events sorted by end time.\n\
derekmu
NORMAL
2023-02-02T05:33:36.354310+00:00
2023-02-02T05:33:36.354360+00:00
52
false
# Intuition\n\nConsider each event ordered by start time while keeping track of the largest already completed event in a copy of the events sorted by end time.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ for sorting.\n\n- Space complexity: $$O(n)$$ for a copy of the events.\n\n# Code\n```\nfunc maxTwoEvents(es [][...
2
0
['Go']
0
two-best-non-overlapping-events
Python - Brute Force ➜ Binary Search ➜ Min Heap ✅
python-brute-force-binary-search-min-hea-02m4
1. BRUTE FORCE APPROACH - O(N^2)\n\nIn Brute Force approach, we just do what the problem asks us to do. We don\'t care about how efficient this solution is. But
itsarvindhere
NORMAL
2022-10-30T13:33:08.113795+00:00
2023-10-09T08:42:09.246525+00:00
116
false
## **1. BRUTE FORCE APPROACH - O(N^2)**\n\nIn Brute Force approach, we just do what the problem asks us to do. We don\'t care about how efficient this solution is. But if you are able to write a Brute Force Approach, you can think of an Optimized Solution easily.\n\nSince we are asked to find two non overlapping events...
2
0
['Binary Search', 'Binary Tree', 'Python']
1
two-best-non-overlapping-events
C++ | DP Memorization + Binary Search | 60% Fast | Easy to Follow Code
c-dp-memorization-binary-search-60-fast-fx5j8
Please Upvote :)\n\n\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n sort(events.begin(),events.end());\n vector
ankit4601
NORMAL
2022-07-27T10:05:34.954758+00:00
2022-07-27T10:05:34.954791+00:00
671
false
Please Upvote :)\n\n```\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n sort(events.begin(),events.end());\n vector<vector<int>> dp(events.size(),vector<int>(2,-1));\n return fun(events,dp,0,0);\n }\n int fun(vector<vector<int>>& v,vector<vector<int>>& dp,int...
2
0
['Dynamic Programming', 'C', 'Sorting', 'Binary Tree', 'C++']
0
two-best-non-overlapping-events
[C++] Sort + Suffix Max + Binary Search || Very Clean Code || Detailed Explanation
c-sort-suffix-max-binary-search-very-cle-cgtc
We solve the problem in 3 steps:\nStep 1 - Sort the events based on starting time.\n\nStep 2 - For every event (Starting from the last event), we find the maxim
varun09
NORMAL
2022-01-15T20:15:19.572024+00:00
2022-01-15T20:17:52.290296+00:00
147
false
**We solve the problem in 3 steps:**\n***Step 1*** - Sort the events based on starting time.\n\n***Step 2*** - For every event (Starting from the last event), we find the maximum value we can get if we go to any event starting after that (Including the current event). \nWe store that value in a map, where, Key -> Start...
2
0
['Binary Search', 'Sorting']
0
two-best-non-overlapping-events
C# Binary Search + Max Value caching
c-binary-search-max-value-caching-by-cle-rjc8
\npublic class Solution {\n public int MaxTwoEvents(int[][] events) {\n Array.Sort(events, (x,y) => x[0].CompareTo(y[0]));\n int[] cache = new
clewby
NORMAL
2021-12-01T20:27:35.055653+00:00
2021-12-01T20:29:23.618981+00:00
113
false
```\npublic class Solution {\n public int MaxTwoEvents(int[][] events) {\n Array.Sort(events, (x,y) => x[0].CompareTo(y[0]));\n int[] cache = new int[events.Length];\n cache[cache.Length-1] = events[events.Length-1][2];\n for(int i = events.Length-2; i >= 0; i--) {\n cache[i...
2
0
['Binary Tree']
1
two-best-non-overlapping-events
Different position of comparator function gives timeout, anyone explain?
different-position-of-comparator-functio-dka7
First I place comparotor function inside the Solution class in public scope by making the comparator function static, it is giving TLE.\nThen I go through the o
nishantjain1501
NORMAL
2021-11-06T12:46:24.321685+00:00
2021-11-07T07:13:44.747333+00:00
132
false
First I place comparotor function inside the Solution class in public scope by making the comparator function static, it is giving TLE.\nThen I go through the other solutions and put the comparator function in different structure now code is working fine. Can anyone please explain?\n\n```\nstruct cmp {\n bool operat...
2
0
['C', 'Sorting', 'C++']
0
two-best-non-overlapping-events
c++ simple O(n*logn) solution
c-simple-onlogn-solution-by-hanzhoutang-r8a7
\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n sort(events.begin(),events.end(),[](auto& a, auto& b) {\n re
hanzhoutang
NORMAL
2021-11-06T03:21:42.397356+00:00
2021-11-06T03:21:42.397384+00:00
228
false
```\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n sort(events.begin(),events.end(),[](auto& a, auto& b) {\n return a[0] < b[0];\n });\n int v = events.back()[2];\n map<int,int> m; \n for(int i = events.size()-1;i>=0;i--) {\n v =...
2
0
[]
1
two-best-non-overlapping-events
TreeMap (SortedMap solution)
treemap-sortedmap-solution-by-jay-lkyk
\nimport java.util.Optional;\n\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // 1. sort by starting time. O(nlogn)\n // 2. ma
jay
NORMAL
2021-11-05T21:40:25.294019+00:00
2021-11-05T21:40:25.294055+00:00
124
false
```\nimport java.util.Optional;\n\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n // 1. sort by starting time. O(nlogn)\n // 2. map of x -> y meaning for all events starting >=x, y=max value . O(n)\n // 3. iterate again, for each end position, find map.get(end+1).\n Arrays...
2
0
[]
1
two-best-non-overlapping-events
Very easy c++ solution Check IT !
very-easy-c-solution-check-it-by-bibhabe-jxe6
New method to use max-heap queue to min heap \n int maxTwoEvents(vector>& events) {\n int n = events.size();\n int maxValue = 0;\n int ans
BibhabenduMukherjee
NORMAL
2021-11-03T05:52:27.223784+00:00
2021-11-03T05:52:27.223814+00:00
81
false
# New method to use max-heap queue to min heap \n** int maxTwoEvents**(vector<vector<int>>& events) {\n int n = events.size();\n int maxValue = 0;\n int ans = 0;\n // take pq (max heap)\n priority_queue<pair<int, pair<int,int>>> pq;\n sort(events.begin() , events.end());\n ...
2
0
[]
0
two-best-non-overlapping-events
Java | sort | sweep line | no DP or BST or TreeMap
java-sort-sweep-line-no-dp-or-bst-or-tre-hur6
Solution 1 -- sweep line\n\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n List<int[]> list = new ArrayList<>();\n for(int i =
qin10
NORMAL
2021-11-02T19:26:40.492981+00:00
2021-11-02T19:50:48.658681+00:00
127
false
Solution 1 -- sweep line\n```\nclass Solution {\n public int maxTwoEvents(int[][] events) {\n List<int[]> list = new ArrayList<>();\n for(int i = 0; i < events.length; ++i) {\n int[] arrStart = new int[]{events[i][0], 1, events[i][2]}; // {startTime, 1, value}\n int[] ...
2
0
[]
0
two-best-non-overlapping-events
C++ with comments | Easy Explanation | Map STL
c-with-comments-easy-explanation-map-stl-7mqb
\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& e) {\n \n map<int,int>startTimeAndMaxi ; \n \n int maximum =
shreyas_010701
NORMAL
2021-10-31T07:32:19.098564+00:00
2021-10-31T07:32:19.098608+00:00
144
false
```\nclass Solution {\npublic:\n int maxTwoEvents(vector<vector<int>>& e) {\n \n map<int,int>startTimeAndMaxi ; \n \n int maximum = 0 ; \n int answer = 0 ; \n \n sort(e.begin() , e.end()) ; // Sorted acc. to StartTime\n \n int size = e.size() ; \n ...
2
0
['Dynamic Programming', 'C']
1
two-best-non-overlapping-events
Simple code with Explanation and Analysis | Binary search
simple-code-with-explanation-and-analysi-r0a0
\n\nApproach:\n Sort events by startTime and traverse from event with highest startTime\n While traversing If we can find an event whose startTime > endTime of
bitmasker
NORMAL
2021-10-31T04:33:35.038060+00:00
2021-10-31T04:33:35.038096+00:00
125
false
<br>\n\n**Approach:**\n* Sort events by startTime and traverse from event with highest startTime\n* While traversing If we can find an event whose startTime > endTime of current event then it means we can take these two in our answer set and we will update the answer accordingly\nelse we can only take the current event...
2
0
['C', 'Sorting', 'Binary Tree']
1
two-best-non-overlapping-events
C++ || Using Sorting Technique || Simple ||
c-using-sorting-technique-simple-by-kund-kvjg
\tclass Solution {\n\tpublic:\n int maxTwoEvents(vector>& events) {\n int res=0;\n int emax=0;\n vector> start;\n vector> end;\n
kundankumar4348
NORMAL
2021-10-31T00:22:02.265962+00:00
2021-10-31T00:22:02.266021+00:00
89
false
\tclass Solution {\n\tpublic:\n int maxTwoEvents(vector<vector<int>>& events) {\n int res=0;\n int emax=0;\n vector<pair<int,int>> start;\n vector<pair<int,int>> end;\n for(int i=0;i<events.size();++i)\n start.push_back({events[i][0],events[i][2]});\n for(int i=0;...
2
0
[]
0
two-best-non-overlapping-events
javascript sort + pre max sum 876ms
javascript-sort-pre-max-sum-876ms-by-hen-h7zf
\nconst maxTwoEvents = (a) => {\n let d = [], res = 0, maxPreSum = 0;\n for (const [start, end, sum] of a) {\n d.push([start, sum, 1]);\n d.
henrychen222
NORMAL
2021-10-30T16:53:05.134570+00:00
2021-10-30T16:53:05.134599+00:00
204
false
```\nconst maxTwoEvents = (a) => {\n let d = [], res = 0, maxPreSum = 0;\n for (const [start, end, sum] of a) {\n d.push([start, sum, 1]);\n d.push([end, sum, -1])\n }\n d.sort((x, y) => {\n if (x[0] != y[0]) return x[0] - y[0];\n return y[2] - x[2];\n });\n for (const [, s...
2
0
['Sorting', 'JavaScript']
0
two-best-non-overlapping-events
Python | O(nlogn) solution | sort, binary search
python-onlogn-solution-sort-binary-searc-mgrg
\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n events.sort()\n N = len(events)\n\n start, end, vals = [],
ilyas_01
NORMAL
2021-10-30T16:46:36.406962+00:00
2021-10-30T18:50:09.828760+00:00
160
false
```\nclass Solution:\n def maxTwoEvents(self, events: List[List[int]]) -> int:\n events.sort()\n N = len(events)\n\n start, end, vals = [], [], []\n for s,e,v in events:\n start.append(s)\n end.append(e)\n vals.append(v)\n \n max_at_index = {...
2
1
['Sorting', 'Binary Tree', 'Python']
0
two-best-non-overlapping-events
[Java] Simple solution using TreeMap - binary search, storing past max profit for the exit time
java-simple-solution-using-treemap-binar-mmrz
Simple Steps:\n1. Split each event into 2 sub events - start and end (identify by -ve value of profit)\n2. If new start sub event comes see if the maxProfit pr
mystic13
NORMAL
2021-10-30T16:10:45.810440+00:00
2021-10-30T16:14:45.191751+00:00
169
false
**Simple Steps:**\n1. Split each event into 2 sub events - start and end (identify by -ve value of profit)\n2. If new start sub event comes see if the maxProfit present in an end sub event which was before current start using TreeMap lowerEntry function.\n3. When end sub event comes store maxRemoved and make an entry ...
2
0
['Binary Tree', 'Java']
1
two-best-non-overlapping-events
Intuitive way
intuitive-way-by-sohailalamx-g1r9
IntuitionApproachComplexityCode
sohailalamx
NORMAL
2025-02-10T19:56:15.824884+00:00
2025-02-10T19:56:15.824884+00:00
12
false
# Intuition 1. I took a i'th interval. Now I can take another interval iff the another one not overlap means eighter that interval will start after the current's end time or that interval will end before current's start time. 2. For each interval I will get start, end, value. So I can keep max ...
1
0
['C++']
0
two-best-non-overlapping-events
Easy sorting and min heap solution
easy-sorting-and-min-heap-solution-by-he-9jrd
IntuitionApproachComplexity Time complexity: Space complexity: Code
hee_maan_shee
NORMAL
2025-01-17T09:34:48.286012+00:00
2025-01-17T09:34:48.286012+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 `...
1
0
['Sorting', 'Heap (Priority Queue)', 'Java']
0
two-best-non-overlapping-events
C# Solution for Two Best Non-Overlapping Events Problem
c-solution-for-two-best-non-overlapping-mknm1
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to find the maximum sum of values from two non-overlapping events. Inste
Aman_Raj_Sinha
NORMAL
2024-12-08T22:05:49.536023+00:00
2024-12-08T22:05:49.536051+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to find the maximum sum of values from two non-overlapping events. Instead of comparing every possible pair of events (which would be inefficient), we break events into start and end points and process them in chronological...
1
0
['C#']
0
two-best-non-overlapping-events
Java Solution for Two Best Non-Overlapping Events Problem
java-solution-for-two-best-non-overlappi-e3lp
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to find the maximum sum of values of two non-overlapping events. To solv
Aman_Raj_Sinha
NORMAL
2024-12-08T22:01:17.884778+00:00
2024-12-08T22:01:17.884809+00:00
12
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to find the maximum sum of values of two non-overlapping events. To solve it efficiently:\n\u2022\tWe leverage the timeline of events by breaking them into start and end points.\n\u2022\tBy sweeping through these points in ...
1
0
['Java']
0
two-best-non-overlapping-events
Swift | Consider all the event points
swift-consider-all-the-event-points-by-p-4qgl
Code\nswift []\nclass Solution {\n func maxTwoEvents(_ events: [[Int]]) -> Int {\n // Every event has 2 points: its start and its end.\n enum E
pagafan7as
NORMAL
2024-12-08T17:54:21.274531+00:00
2024-12-08T18:03:06.304788+00:00
17
false
# Code\n```swift []\nclass Solution {\n func maxTwoEvents(_ events: [[Int]]) -> Int {\n // Every event has 2 points: its start and its end.\n enum EventType: Int { case start = 1, end = 0 }\n typealias EventPoint = (type: EventType, time: Int, value: Int)\n\n // Construct the different ev...
1
0
['Swift']
0
two-best-non-overlapping-events
✅Maximum Sum of Two Non-Overlapping Events Using Binary Search🚀Beats💯
maximum-sum-of-two-non-overlapping-event-47a8
Intuition:\n\nTo maximize the sum of values of two non-overlapping events, we need to:\n1. Identify two events such that their times do not overlap (i.e., the s
ranganathv415
NORMAL
2024-12-08T17:31:07.747014+00:00
2024-12-08T17:31:07.747037+00:00
29
false
# Intuition:\n\nTo maximize the sum of values of two non-overlapping events, we need to:\n1. Identify two events such that their times do not overlap (i.e., the start time of one is after the end time of the other).\n2. Leverage the sorted structure of events to efficiently find compatible pairs, maximizing their combi...
1
0
['TypeScript']
0
two-best-non-overlapping-events
Binary Search & Suffix Array
binary-search-suffix-array-by-himanshu_1-xrzm
Intuition\nThe basic idea is that for every event, the result can either be the current event\'s value or the current event\'s value plus the maximum value of s
himanshu_1998
NORMAL
2024-12-08T17:02:15.561178+00:00
2024-12-08T17:02:15.561215+00:00
10
false
# Intuition\nThe basic idea is that for every event, the result can either be the current event\'s value or the current event\'s value plus the maximum value of some future non-overlapping event. To efficiently find the next non-overlapping event, we can jump directly to the interval that starts after the current one e...
1
0
['Java']
1
two-best-non-overlapping-events
Two Best Non-Overlapping Events | C++ | Sorting | NlogN
two-best-non-overlapping-events-c-sortin-ml3u
Complexity\n- Time complexity: O(nlogn)\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(n) \n\n
JeetuGupta
NORMAL
2024-12-08T16:18:19.018978+00:00
2024-12-08T16:18:19.019014+00:00
13
false
# Complexity\n- Time complexity: $$O(nlogn)$$\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(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n int findNextNonOverlapping(vector<vector<int>> &events, int l){\n int start = 0,...
1
0
['C++']
0