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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
divide-intervals-into-minimum-number-of-groups | Line sweep-> sort -> radix sort||153ms beats 100% | line-sweep-sort-radix-sort153ms-beats-10-16i2 | Intuition\n Describe your first thoughts on how to solve this problem. \nThis question can be solved with line sweep; it takes $O(n\uFF0B\max(right)+1)$ time wh | anwendeng | NORMAL | 2024-10-12T03:05:52.932896+00:00 | 2024-10-12T06:54:49.203955+00:00 | 2,179 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question can be solved with line sweep; it takes $O(n\uFF0B\\max(right)+1)$ time where right<=1e6.\n\nUsing sort it can be reduced to $O(n\\log n)$ time. If other sorting method is applied, the time complexity can be furthermore redu... | 18 | 0 | ['Array', 'Line Sweep', 'Sorting', 'C++'] | 6 |
divide-intervals-into-minimum-number-of-groups | [C++] Similar to minimum plateforms required problem | c-similar-to-minimum-plateforms-required-oznu | \nclass Solution {\npublic:\n bool static comp(vector<int> &a,vector<int> &b) {\n return a[1]<b[1];\n }\n int minGroups(vector<vector<int>>& int | Ayush479 | NORMAL | 2022-09-11T05:23:45.555631+00:00 | 2022-09-11T05:23:45.555681+00:00 | 1,128 | false | ```\nclass Solution {\npublic:\n bool static comp(vector<int> &a,vector<int> &b) {\n return a[1]<b[1];\n }\n int minGroups(vector<vector<int>>& intervals) {\n // Your code here\n vector<int>arr,dep;\n int n=intervals.size();\n for(auto x:intervals){\n arr.push_back... | 15 | 0 | ['C', 'Sorting'] | 2 |
divide-intervals-into-minimum-number-of-groups | C++ || Priority Queue | c-priority-queue-by-kirtipurohit025-ivc0 | \nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n priority_queue<int, vector<int>, greater<int>> pq;\n \n | kirtipurohit025 | NORMAL | 2022-09-11T04:09:31.216637+00:00 | 2022-09-11T04:09:31.216674+00:00 | 1,218 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n priority_queue<int, vector<int>, greater<int>> pq;\n \n sort(intervals.begin(), intervals.end()); \n int ans=0;\n for (auto inter: intervals) {\n int start= inter[0], end= inter[1]; \n ... | 15 | 1 | ['C'] | 4 |
divide-intervals-into-minimum-number-of-groups | Simplest way || Prefix Sum || O(n) | simplest-way-prefix-sum-on-by-priyanshuh-4a51 | \nint minGroups(vector<vector<int>>& nums) {\n int n = INT_MIN;\n for(int i=0;i<nums.size();i++)\n n = max(n, nums[i][1]);\n \n | priyanshuHere27 | NORMAL | 2022-09-11T04:02:13.594059+00:00 | 2022-09-11T04:02:13.594115+00:00 | 2,391 | false | ```\nint minGroups(vector<vector<int>>& nums) {\n int n = INT_MIN;\n for(int i=0;i<nums.size();i++)\n n = max(n, nums[i][1]);\n \n vector<int> v(n+2, 0);\n for(int i=0;i<nums.size();i++)\n {\n v[nums[i][0]]++;\n v[nums[i][1]+1]--;\n }\n ... | 15 | 0 | ['C', 'Prefix Sum', 'C++'] | 9 |
divide-intervals-into-minimum-number-of-groups | Python | Sweep Line Pattern | python-sweep-line-pattern-by-khosiyat-8hjc | see the Successfully Accepted Submission\n\n# Code\npython3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n events = [ | Khosiyat | NORMAL | 2024-10-12T02:28:47.830223+00:00 | 2024-10-12T02:28:47.830246+00:00 | 1,034 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/submissions/1419533602/?envType=daily-question&envId=2024-10-12)\n\n# Code\n```python3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n events = []\n \n... | 13 | 0 | ['Python3'] | 2 |
divide-intervals-into-minimum-number-of-groups | Python3 || 5 lines, dict, accumulate || T/S: 62% / 21% | python3-5-lines-dict-accumulate-ts-62-21-7uzn | \n\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n\n d = defaultdict(int)\n\n for start, end in intervals:\n | Spaulding_ | NORMAL | 2022-09-15T21:06:56.395301+00:00 | 2024-06-14T18:06:53.751150+00:00 | 402 | false | \n```\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n\n d = defaultdict(int)\n\n for start, end in intervals:\n d[start]+= 1\n d[end+1]-= 1\n\n return max(accumulate([d[n] for n in sorted(d)]))\n```\t\t\n[https://leetcode.com/problems/divide-int... | 12 | 1 | ['Python', 'Python3'] | 1 |
divide-intervals-into-minimum-number-of-groups | 🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line | leetcode-the-hard-way-explained-line-by-uj7mx | Please check out LeetCode The Hard Way for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full li | __wkw__ | NORMAL | 2022-09-12T04:50:55.289156+00:00 | 2022-09-12T04:50:55.289199+00:00 | 753 | false | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full list in my [Discord](https://discord.gg/Nqm4jJcyBf).\nIf you like it, please give a star, watch my [Github R... | 11 | 0 | ['C', 'Prefix Sum', 'C++'] | 4 |
divide-intervals-into-minimum-number-of-groups | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-6xh8 | Using Sorting && Min. Heap\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& a | __KR_SHANU_IITG | NORMAL | 2022-09-11T05:24:41.725965+00:00 | 2022-09-11T05:24:41.725994+00:00 | 820 | false | * ***Using Sorting && Min. Heap***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& arr) {\n \n int n = arr.size();\n \n // sort the array on the basis of start in increasing order\n \n... | 9 | 1 | ['C', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | python/java heap | pythonjava-heap-by-akaghosting-tfjs | \tclass Solution:\n\t\tdef minGroups(self, intervals: List[List[int]]) -> int:\n\t\t\tintervals.sort()\n\t\t\tminHeap = []\n\t\t\tfor left, right in intervals:\ | akaghosting | NORMAL | 2022-09-11T04:01:11.833490+00:00 | 2022-09-11T04:01:11.833527+00:00 | 544 | false | \tclass Solution:\n\t\tdef minGroups(self, intervals: List[List[int]]) -> int:\n\t\t\tintervals.sort()\n\t\t\tminHeap = []\n\t\t\tfor left, right in intervals:\n\t\t\t\tif minHeap and left > minHeap[0]:\n\t\t\t\t\theapq.heappop(minHeap)\n\t\t\t\theapq.heappush(minHeap, right)\n\t\t\treturn len(minHeap)\n\n\n\tclass Sol... | 9 | 1 | [] | 0 |
divide-intervals-into-minimum-number-of-groups | C++ Line Sweep | c-line-sweep-by-abhay5349singh-ckae | Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nIntuition\n1. By sweep[l]++ & sweep[r+1]--, we are acknowledging the presence of a p | abhay5349singh | NORMAL | 2022-09-11T04:30:39.327051+00:00 | 2023-07-14T03:49:47.798828+00:00 | 1,260 | false | **Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Intuition**\n1. By sweep[l]++ & sweep[r+1]--, we are acknowledging the presence of a particular interval b/w [l,r].\n 2. by taking the cumulative sum over this sweep array gives a count of overlapping intervals present at any certain poin... | 8 | 0 | ['C++'] | 5 |
divide-intervals-into-minimum-number-of-groups | Simplest way || Min Heap || Java Solution | simplest-way-min-heap-java-solution-by-p-wqg5 | \n\n\n\n\nclass Solution {\n public int minGroups(int[][] intervals) {\n \n PriorityQueuepq=new PriorityQueue<>();\n \n Arrays.so | Prabhat_17 | NORMAL | 2022-09-11T08:32:56.127875+00:00 | 2022-09-11T08:32:56.127899+00:00 | 722 | false | \n\n\n\n\nclass Solution {\n public int minGroups(int[][] intervals) {\n \n PriorityQueue<Integer>pq=new PriorityQueue<>();\n \n Arrays.sort(intervals,(a,b)->(a[0]==b[0])?a[1]-b[1]:a[0]-b[0]);\n \n for(int[] arr:intervals){\n if(pq.size()>0 && pq.peek()<arr[0]){\n... | 7 | 0 | ['Heap (Priority Queue)', 'Java'] | 2 |
divide-intervals-into-minimum-number-of-groups | C++ || Easy without Priority Queue✅✅ | c-easy-without-priority-queue-by-arunk_l-b984 | Intuition\nThe problem can be solved by considering the number of overlapping intervals at any given point. By treating the start and end of intervals as separa | arunk_leetcode | NORMAL | 2024-10-12T04:47:47.602944+00:00 | 2024-10-12T04:47:47.602978+00:00 | 1,419 | false | # Intuition\nThe problem can be solved by considering the number of overlapping intervals at any given point. By treating the start and end of intervals as separate events, we can track the number of intervals active at any point in time. The maximum number of intervals active simultaneously is the answer.\n\n# Approac... | 6 | 0 | ['Sorting', 'C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | Intuitive Binary Search Approach ( With Comments ) | intuitive-binary-search-approach-with-co-ebv7 | \n // Please Upvote , if you find this logic intuitive :)\n \n int minGroups(vector>& v) {\n int n = v.size(); // Initialising the Size of given | tHe_lAZy_1 | NORMAL | 2022-09-11T07:13:07.917981+00:00 | 2022-09-11T08:37:05.433631+00:00 | 805 | false | \n // Please Upvote , if you find this logic intuitive :)\n \n int minGroups(vector<vector<int>>& v) {\n int n = v.size(); // Initialising the Size of given matrix\n \n vector<pair<int,int>>p; // Initialising a vector of pair \n \n /*\n Initialising a multiset of ... | 6 | 0 | ['Binary Search', 'Greedy', 'C', 'Sorting', 'Binary Tree', 'C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | ✅ One Line Solution | one-line-solution-by-mikposp-q5x9 | (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 - One Line\nTime complexity: O(n*log | MikPosp | NORMAL | 2024-10-12T19:37:52.750819+00:00 | 2024-10-12T19:37:52.750834+00:00 | 211 | false | (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 - One Line\nTime complexity: $$O(n*log(n))$$. Space complexity: $$O(n)$$.\n```python3\nclass Solution:\n def minGroups(self, a: List[List[int]]) -> int:\n return len((q:=[],[(q and q[0]<... | 5 | 1 | ['Array', 'Sorting', 'Heap (Priority Queue)', 'Python', 'Python3'] | 3 |
divide-intervals-into-minimum-number-of-groups | 💡Easy Solution | O (n log n) | C++ 175ms Beats 99.77% | Minimum Number of Groups | 🧠 | easy-solution-o-n-log-n-c-175ms-beats-99-kvsb | \n\n#\n---\n> # Intuition \nTo solve this problem, we need to group the intervals such that no two intervals in the same group intersect. By sorting the interv | user4612MW | NORMAL | 2024-10-12T04:36:40.456737+00:00 | 2024-10-12T04:41:07.907957+00:00 | 305 | false | \n\n#\n---\n> # Intuition \nTo solve this problem, we need to group the intervals such that no two intervals in the same group intersect. By sorting the intervals\' start and end times and using a greedy approach, we can track how many intervals are active at any given time and determine the minimum number of groups r... | 5 | 0 | ['C++'] | 3 |
divide-intervals-into-minimum-number-of-groups | Easy Solution | easy-solution-by-viratkohli-ojob | 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\ | viratkohli_ | NORMAL | 2024-10-12T02:51:13.779799+00:00 | 2024-10-12T02:51:13.779832+00:00 | 310 | false | # 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```cpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n priority_queue<int, vector<i... | 5 | 0 | ['Array', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | I'm a Beginner/Newbie just like you! | im-a-beginnernewbie-just-like-you-by-sat-8btd | Intuition\n- Try meeting rooms 3 before this problem. (ofc thats much harder than this, but if u dont get that one also-once try it for better understanding of | satwika-55 | NORMAL | 2024-10-12T02:17:08.959774+00:00 | 2024-10-12T02:18:48.078415+00:00 | 274 | false | # Intuition\n- Try meeting rooms 3 before this problem. (ofc thats much harder than this, but if u dont get that one also-once try it for better understanding of this question)\n\n# Code\n```python3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n # afterall, who can give you mo... | 5 | 2 | ['Python3'] | 1 |
divide-intervals-into-minimum-number-of-groups | EASY SOLUTION USING SET FOR BEGINNERS!!! | easy-solution-using-set-for-beginners-by-vq8x | 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 | aero_coder | NORMAL | 2024-10-12T00:33:08.778370+00:00 | 2024-10-12T00:59:34.212338+00:00 | 779 | 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)$$ --... | 5 | 0 | ['C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | Solution similar to 253. Meeting Rooms II (similar problems listed) | solution-similar-to-253-meeting-rooms-ii-wuov | Please see and vote for my solutions for similar problems.\n253. Meeting Rooms II\n2406. Divide Intervals Into Minimum Number of Groups\n2402. Meeting Rooms III | otoc | NORMAL | 2022-09-19T00:43:22.264903+00:00 | 2022-09-19T14:50:38.694782+00:00 | 909 | false | Please see and vote for my solutions for similar problems.\n[253. Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/discuss/322622/Simple-Python-solutions)\n[2406. Divide Intervals Into Minimum Number of Groups](https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/discuss/2594874/... | 5 | 0 | [] | 0 |
divide-intervals-into-minimum-number-of-groups | ✅Something New || Something Different || Using Fenwick Tree || (◍•ᴗ•◍) | something-new-something-different-using-itp5u | Approach\n Describe your approach to solving the problem. \nOne of the key observations in this question is that the minimum number of groups needed to divide t | Arcturus_22 | NORMAL | 2024-10-12T05:27:47.635350+00:00 | 2024-10-12T08:07:31.898760+00:00 | 271 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nOne of the key observations in this question is that the minimum number of groups needed to divide the intervals corresponds to the maximum number of intervals that a number lies in, or in other words, the maximum number of overlapping intervals at an... | 4 | 0 | ['Binary Indexed Tree', 'C++', 'Java'] | 2 |
divide-intervals-into-minimum-number-of-groups | 2Ways || StepWise ||JAVA C++ PYTHON. | 2ways-stepwise-java-c-python-by-abhishek-lq6b | BOISS JUST UPVOTE , I WORK SO HARD WRITNG THIS OUT AND YOU SHAMELESS PEOPLE SONT EVEN LIKE THE POST . PLS UPVOTE IT.\n# METHOD 1.)\n\n### Steps:\n\n1. Sort the | Abhishekkant135 | NORMAL | 2024-10-12T04:58:09.111092+00:00 | 2024-10-12T08:03:12.841630+00:00 | 563 | false | # BOISS JUST UPVOTE , I WORK SO HARD WRITNG THIS OUT AND YOU SHAMELESS PEOPLE SONT EVEN LIKE THE POST . PLS UPVOTE IT.\n# METHOD 1.)\n\n### Steps:\n\n1. Sort the intervals by their start time.\n2. Use a priority queue to track the end times of the intervals.\n3. For each interval, check if the current interval can be g... | 4 | 0 | ['Two Pointers', 'Sorting', 'Heap (Priority Queue)', 'Python', 'C++', 'Java'] | 2 |
divide-intervals-into-minimum-number-of-groups | let's step by step Understand Intuition, with added YouTube link | lets-step-by-step-understand-intuition-w-8wbi | YouTube link https://youtu.be/RpL05RSTUF0\n# Intuition and Approach\nas we have intervals array then if we traverse through intervals array ==> if we maintain a | vinod_aka_veenu | NORMAL | 2024-10-12T03:46:05.588510+00:00 | 2024-10-12T06:57:32.617314+00:00 | 977 | false | # YouTube link https://youtu.be/RpL05RSTUF0\n# Intuition and Approach\nas we have intervals array then if we traverse through intervals array ==> if we maintain a Ordered Map we can keep on increasing count at **start** value in MAP by 1 AND **decrease** the count at **(end + 1)** by 1.\n\n**you might have question, w... | 4 | 0 | ['Array', 'Math', 'Ordered Map', 'Counting Sort', 'C++', 'Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | Faster || Efficient Approach || C++ || Divide intervals into minimum number of groups | faster-efficient-approach-c-divide-inter-jip5 | 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 | Shuklajii109 | NORMAL | 2024-10-12T03:24:06.262011+00:00 | 2024-10-12T03:24:06.262030+00:00 | 333 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $... | 4 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Prefix Sum', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | 37ms nlogn Beats 100% - two sorted vecs for start and end of interval. Count up and down and track. | 37ms-nlogn-beats-100-two-sorted-vecs-for-pngd | Intuition\nThe question is really saying "what\'s the max intersections at one time", and that\'s something we can find with a counter and a max. Keep track of | jkoudys | NORMAL | 2024-10-12T02:15:06.003603+00:00 | 2024-10-12T12:45:12.867680+00:00 | 221 | false | # Intuition\nThe question is really saying "what\'s the max intersections at one time", and that\'s something we can find with a counter and a max. Keep track of how many ranges are active.\n\n# Approach\nWe do two sorts. One against a Vec of the interval start positions, and one against the end. Then we keep checking ... | 4 | 0 | ['Array', 'PHP', 'Sorting', 'TypeScript', 'Rust'] | 2 |
divide-intervals-into-minimum-number-of-groups | C#| Line Sweep Algo | c-line-sweep-algo-by-krishnamhn009-1m57 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nLine sweep algorithm\n Describe your approach to solving the problem. \n\ | krishnamhn009 | NORMAL | 2024-05-04T19:17:06.869810+00:00 | 2024-05-04T19:17:06.869857+00:00 | 115 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nLine sweep algorithm\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- O(n+k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space c... | 4 | 0 | ['C#'] | 1 |
divide-intervals-into-minimum-number-of-groups | [Python 3] Line Sweep - Difference Array | python-3-line-sweep-difference-array-by-8w6q6 | 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 | dolong2110 | NORMAL | 2023-05-06T17:55:35.626389+00:00 | 2023-05-06T17:55:35.626487+00:00 | 308 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here... | 4 | 0 | ['Array', 'Prefix Sum', 'Python3'] | 1 |
divide-intervals-into-minimum-number-of-groups | Line Sweep Method | O(n) Solution | line-sweep-method-on-solution-by-dsharma-ence | ```\n//\t\tLine sweep methods is used when all the queries are done and we have to find\n//\t\tsome answer after that.\n\t\t\n//\t\tAssign Line array with all 0 | dsharma007 | NORMAL | 2022-09-30T20:33:19.544278+00:00 | 2022-09-30T20:38:11.909016+00:00 | 291 | false | ```\n//\t\tLine sweep methods is used when all the queries are done and we have to find\n//\t\tsome answer after that.\n\t\t\n//\t\tAssign Line array with all 0\'s.\n//\t\tLine sweep method for range(low, right) to add k works as follows:-\n//\t\t\t-> assign line[low] = k and assign line[right + 1] = -k;\n//\t\t\t-> No... | 4 | 0 | ['Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++ || All methods summarised | c-all-methods-summarised-by-dash28-1ly5 | Method 1 (Optimised Brute Force)\n\nI am sure this was one of the questions you would want to avoid if you haven\'t solved questions on Line-sweep or interval m | Dash28 | NORMAL | 2022-09-11T06:58:51.401458+00:00 | 2022-09-11T10:21:55.990617+00:00 | 237 | false | Method 1 (Optimised Brute Force)\n\nI am sure this was one of the questions you would want to avoid if you haven\'t solved questions on Line-sweep or interval merging before. So I was trying to come up with a simple approach that a person might take up without any prior knowledge on how to go about merging intervals th... | 4 | 0 | ['C'] | 2 |
divide-intervals-into-minimum-number-of-groups | sorting approach with two pointers | sorting-approach-with-two-pointers-by-ka-i1m5 | Intuition\nEarliest interval comes first. when an intervals comes, it will be checked for an empty group based on minimum end time of any interval already exist | kanna-naveen | NORMAL | 2024-10-12T14:09:51.096132+00:00 | 2024-10-12T14:09:51.096157+00:00 | 24 | false | # Intuition\nEarliest interval comes first. when an intervals comes, it will be checked for an empty group based on minimum end time of any interval already existed in any group. empty group indicates that already existed minimum end time is smaller than current start time.\n\n# Complexity\n- Time complexity:\nstoring ... | 3 | 0 | ['Two Pointers', 'Sorting', 'Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | Go solution with the explanation | go-solution-with-the-explanation-by-alek-x8jy | Intuition\n\nThe key challenge here is determining how many overlapping intervals we can have at any given time. If two intervals overlap, they must be in separ | alekseiapa | NORMAL | 2024-10-12T07:35:48.210375+00:00 | 2024-10-12T07:35:48.210399+00:00 | 68 | false | # Intuition\n\nThe key challenge here is determining how many overlapping intervals we can have at any given time. If two intervals overlap, they must be in separate groups. We can visualize this problem similarly to the "meeting rooms" problem, where overlapping meetings need separate rooms.\n\nTo solve this efficient... | 3 | 0 | ['Go'] | 0 |
divide-intervals-into-minimum-number-of-groups | C++ Solution || Easy to Understand || Without heap | c-solution-easy-to-understand-without-he-lh6f | Intuition\nThe problem asks for the minimum number of groups required such that no intervals within a group overlap. To solve this, we can think of treating eac | Rohit_Raj01 | NORMAL | 2024-10-12T05:55:55.795041+00:00 | 2024-10-12T05:55:55.795075+00:00 | 276 | false | # Intuition\nThe problem asks for the minimum number of groups required such that no intervals within a group overlap. To solve this, we can think of treating each interval as two events: a `start` event and an `end` event. By processing these events in order, we can keep track of the number of overlapping intervals at... | 3 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | Beats 99.77% | 2 solutions | Priority Queue & Sorting | beats-9977-2-solutions-priority-queue-so-l68e | \n# Intuition\n- For both versions of the solution, the problem can be understood as finding the minimum number of groups required to hold non-overlapping inter | B_I_T | NORMAL | 2024-10-12T05:30:30.409649+00:00 | 2024-10-12T05:30:30.409685+00:00 | 678 | false | \n# Intuition\n- For both versions of the solution, the problem can be understood as finding the minimum number of groups required to hold non-overlapping intervals.\n1. Versio... | 3 | 0 | ['Array', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Java', 'Python3', 'JavaScript'] | 2 |
divide-intervals-into-minimum-number-of-groups | Python | Line Sweep | 89% T 40% S | python-line-sweep-89-t-40-s-by-patrikk-kw68 | Intuition\n\n\nAn alternative approach to this problem is simply "returning the max number of overlapping intervals". \n\nThis can easily be accomplished using | Patrikk_ | NORMAL | 2024-10-12T00:40:18.174934+00:00 | 2024-10-12T00:40:18.174965+00:00 | 181 | false | **Intuition**\n\n\nAn alternative approach to this problem is simply "returning the max number of overlapping intervals". \n\nThis can easily be accomplished using the line-sweep algorithm where we increment the start of our interval by ```1``` and decrement the ```end + 1``` interval by ```1```. We decrement the ```en... | 3 | 0 | ['Sorting', 'Python', 'Python3'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++ || turn into events for opening and closing the intervals | c-turn-into-events-for-opening-and-closi-5hqy | Solution 1: turn into discrete events for the left and right end of the interval and sweep\n\ncpp\n static int minGroups(const vector<vector<int>>& intervals | heder | NORMAL | 2022-09-11T16:26:55.370538+00:00 | 2022-09-11T16:26:55.370580+00:00 | 146 | false | ### Solution 1: turn into discrete events for the left and right end of the interval and sweep\n\n```cpp\n static int minGroups(const vector<vector<int>>& intervals) {\n vector<int> events;\n events.reserve(size(intervals) * 2);\n for (const vector<int>& interval : intervals) {\n cons... | 3 | 0 | ['C'] | 1 |
divide-intervals-into-minimum-number-of-groups | Simple Java Solution || EAsy to understand || O(n) solution | simple-java-solution-easy-to-understand-9c50p | \nclass Solution {\n public int minGroups(int[][] intervals) {\n int m = 0; \n for(int i[] : intervals){\n m = Math.max(m,i[0]);\n | Himanshu_Goyal_517 | NORMAL | 2022-09-11T04:40:03.826395+00:00 | 2022-09-11T04:40:03.826437+00:00 | 308 | false | ```\nclass Solution {\n public int minGroups(int[][] intervals) {\n int m = 0; \n for(int i[] : intervals){\n m = Math.max(m,i[0]);\n m = Math.max(m,i[1]);\n }\n long arr[] = new long[m+2];\n for(int a[] : intervals){\n arr[a[0]] += 1;\n ... | 3 | 0 | ['Prefix Sum', 'Java'] | 2 |
divide-intervals-into-minimum-number-of-groups | c++ solution line sweep | c-solution-line-sweep-by-dilipsuthar60-p2bx | \nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& nums) {\n map<int,int>mp;\n for(auto it:nums)\n {\n mp[it[0] | dilipsuthar17 | NORMAL | 2022-09-11T04:03:15.565770+00:00 | 2022-09-11T04:03:15.565807+00:00 | 231 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& nums) {\n map<int,int>mp;\n for(auto it:nums)\n {\n mp[it[0]]++;\n mp[it[1]+1]--;\n }\n int sum=0;\n for(auto &[a,b]:mp)\n {\n sum+=b;\n b=sum;\n }\n... | 3 | 0 | ['C', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | [Python3] Sort + Heap | python3-sort-heap-by-helnokaly-f7xx | \nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort()\n pq = []\n for interval in intervals:\n | helnokaly | NORMAL | 2022-09-11T04:01:18.846754+00:00 | 2022-09-11T04:18:53.353805+00:00 | 553 | false | ```\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort()\n pq = []\n for interval in intervals:\n if not pq or interval[0] <= pq[0]:\n heapq.heappush(pq, interval[1])\n else:\n\t\t\t\theapq.heappop(pq)\n\t\t\t\theapq.h... | 3 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Python3'] | 0 |
divide-intervals-into-minimum-number-of-groups | [Python3/Rust] Max DP Overlap | python3rust-max-dp-overlap-by-agrpractic-71t6 | Weekly Contest 310 Submission\n\nDisclaimer \nMy contest submission was written in Python3. I attempted submissions after the contest and noticed that this solu | AgrPractice | NORMAL | 2022-09-11T04:00:26.678102+00:00 | 2023-01-16T19:05:53.422291+00:00 | 632 | false | **Weekly Contest 310 Submission**\n\n**Disclaimer** \nMy contest submission was written in ```Python3```. I attempted submissions after the contest and noticed that this solution will TLE on average (as noted by ```xavier-xia-99``` it seems to be an approximate 10% acceptance chance in ```Python3```). Following the con... | 3 | 0 | ['Prefix Sum', 'Python3', 'Rust'] | 3 |
divide-intervals-into-minimum-number-of-groups | sort & priority_queue(simple & easy) | sort-priority_queuesimple-easy-by-kamoji-jghn | Intuition\nWe need to divide the intervals into groups such that no two intervals in the same group overlap. The idea is to keep track of how many groups are ne | kamojishashank00 | NORMAL | 2024-10-19T19:17:33.531929+00:00 | 2024-10-19T19:17:33.531960+00:00 | 6 | false | # Intuition\nWe need to divide the intervals into groups such that no two intervals in the same group overlap. The idea is to keep track of how many groups are needed at a time, using a priority queue (min-heap) to maintain the minimum end times of the groups that are being formed.\n\n# Approach\n<!-- Describe your app... | 2 | 0 | ['Heap (Priority Queue)', 'C++'] | 0 |
divide-intervals-into-minimum-number-of-groups | Most Simple Approach || Fast 100% Beats || Using a Min-Heap | most-simple-approach-fast-100-beats-usin-js8v | Code\npython3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort(key=lambda x: x[0])\n ok = []\n\n | anand_shukla1312 | NORMAL | 2024-10-12T15:07:37.015964+00:00 | 2024-10-12T15:07:37.016004+00:00 | 56 | false | # Code\n```python3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort(key=lambda x: x[0])\n ok = []\n\n for i,j in intervals:\n if ok and ok[0] < i:\n heappop(ok)\n heappush(ok,j)\n \n a = len(ok)\n ... | 2 | 0 | ['Python3'] | 1 |
divide-intervals-into-minimum-number-of-groups | simplest code using 2 pointers | simplest-code-using-2-pointers-by-yourst-g07h | Intuition\nUse 2 pointers\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\npython3 []\nclass Solution:\n def minGroups(s | Yourstruly_priyanshu | NORMAL | 2024-10-12T13:29:46.069909+00:00 | 2024-10-12T13:29:46.069948+00:00 | 9 | false | # Intuition\nUse 2 pointers\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```python3 []\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n s = sorted(i[0] for i in intervals)\n end = sorted(i[1] for i in intervals)\n e, g = 0, 0\n... | 2 | 0 | ['Two Pointers', 'Python3'] | 0 |
divide-intervals-into-minimum-number-of-groups | 🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏 | beats-super-easy-beginners-by-codewithsp-ggdt | \n\n# Intuition\nThe problem asks to find the minimum number of groups that can accommodate overlapping intervals. This can be thought of as an interval schedul | CodeWithSparsh | NORMAL | 2024-10-12T11:11:01.930416+00:00 | 2024-10-12T11:11:01.930449+00:00 | 19 | false | \n\n# Intuition\nThe problem asks to find the minimum number of groups that can accommodate overlapping intervals. This can be thought of as an interval scheduling problem where we need to track how many in... | 2 | 0 | ['C++', 'Python3', 'JavaScript', 'Dart'] | 0 |
divide-intervals-into-minimum-number-of-groups | Original Solution🔥🔥|| Using maps and greedy✍️✍️ || C++ | original-solution-using-maps-and-greedy-5ooeg | Intuition\n Describe your first thoughts on how to solve this problem. \nThe first thought to solving this question is to find out the maximum number of interva | Johnnys_Zero | NORMAL | 2024-10-12T10:25:57.062923+00:00 | 2024-10-12T10:25:57.062968+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe first thought to solving this question is to find out the maximum number of intervals that intersect at a certain point, which will be the minimum number of groups required.\n\n# Approach\n<!-- Describe your approach to solving the pr... | 2 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
divide-intervals-into-minimum-number-of-groups | ✅ Simple Java Solution | simple-java-solution-by-harsh__005-x42y | CODE\n\n### Solution 1:\nJava []\npublic int minGroups(int[][] intervals) {\n\tArrays.sort(intervals, (a,b)->{\n\t\tif(a[0] == b[0]) return a[1]-b[1];\n\t\tretu | Harsh__005 | NORMAL | 2024-10-12T09:15:46.464349+00:00 | 2024-10-12T09:26:42.738793+00:00 | 83 | false | ## **CODE**\n\n### Solution 1:\n```Java []\npublic int minGroups(int[][] intervals) {\n\tArrays.sort(intervals, (a,b)->{\n\t\tif(a[0] == b[0]) return a[1]-b[1];\n\t\treturn a[0]-b[0];\n\t});\n\n\tint n = intervals.length, max = 0, size = 0;\n\tTreeMap<Integer, Integer> map = new TreeMap<>();\n\tfor(int[] inv: intervals... | 2 | 0 | ['Heap (Priority Queue)', 'Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | O(NLogN) solution || Priority Queue || Very easy to understand | onlogn-solution-priority-queue-very-easy-8jk2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Sort the array based | anonymous_now | NORMAL | 2024-10-12T05:45:39.053645+00:00 | 2024-10-12T05:45:39.053668+00:00 | 97 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the array based on left value\n2. We can add a interval in a group if and only if its left value is greater than group max value (max right value)\n3. So we ne... | 2 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Kotlin'] | 1 |
divide-intervals-into-minimum-number-of-groups | Detailed step by step easy explanation || Sweepline || Index Compression || Clean Code || C++ | detailed-step-by-step-easy-explanation-s-ijdg | Approach\n Describe your approach to solving the problem. \nWe consider a sorted array containing t_minimum to t_maximum. \nFor example, consider [5, 10], [6, 8 | shayonp | NORMAL | 2024-10-12T05:27:02.866906+00:00 | 2024-10-12T05:27:02.866938+00:00 | 15 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe consider a sorted array containing t_minimum to t_maximum. \nFor example, consider [5, 10], [6, 8], [1, 5] [2, 3] and [1, 10]. We have to update the array, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],according to each of the intervals.\n\nSo, originally we hav... | 2 | 0 | ['C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | Easy C++ Solution Set Lower Bound | easy-c-solution-set-lower-bound-by-sahil-yfxj | Approach\nFind a end time in set which is just previous to current start time.\n\n# Complexity\n- Time complexity:O(NLogN)\n\n- Space complexity:O(N)\n\n# Code\ | Sahil_0902 | NORMAL | 2024-10-12T04:56:17.648679+00:00 | 2024-10-12T04:56:17.648716+00:00 | 71 | false | # Approach\nFind a end time in set which is just previous to current start time.\n\n# Complexity\n- Time complexity:O(NLogN)\n\n- Space complexity:O(N)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n \n sort(begin(intervals),end(intervals));\n ... | 2 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | Best way to solve in java do not forget to UPVOTE | best-way-to-solve-in-java-do-not-forget-08qnn | Intuition\nWe need to group intervals such that no intervals in the same group overlap. By sorting the intervals based on their start and end times, we can trac | rnt07s | NORMAL | 2024-10-12T04:14:59.495973+00:00 | 2024-10-12T04:14:59.496007+00:00 | 99 | false | # Intuition\nWe need to group intervals such that no intervals in the same group overlap. By sorting the intervals based on their start and end times, we can track how many intervals overlap at any given point. If a new interval starts after an earlier one has ended, we can assign it to the same group. Otherwise, we ne... | 2 | 0 | ['Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | Java Clean Frequency Count Solution | java-clean-frequency-count-solution-by-s-9g1w | Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1_000_002)\n Add your space complexity here, e.g. O(n) \n | Shree_Govind_Jee | NORMAL | 2024-10-12T03:44:39.415817+00:00 | 2024-10-12T03:44:39.415849+00:00 | 277 | false | # Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1_000_002)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public int minGroups(int[][] intervals) {\n int[] cnt = new int[1_000_002];\n... | 2 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Prefix Sum', 'Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | Swift | Event Line | swift-event-line-by-pagafan7as-5kzc | Code\nswift []\nclass Solution {\n // Defines an "event" as the entering or exiting of an interval.\n // It helps to think of those as time intervals.\n | pagafan7as | NORMAL | 2024-10-12T03:38:58.978939+00:00 | 2024-10-12T21:28:01.734009+00:00 | 36 | false | # Code\n```swift []\nclass Solution {\n // Defines an "event" as the entering or exiting of an interval.\n // It helps to think of those as time intervals.\n struct Event: Comparable {\n enum EventType { case enter, exit }\n\n let time: Int\n let type: EventType\n\n static func <(lh... | 2 | 0 | ['Swift'] | 0 |
divide-intervals-into-minimum-number-of-groups | Easy Approach || O(n log(n)) || Python || C++ || Greedy | easy-approach-on-logn-python-c-greedy-by-4rmj | 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 | shra_1906 | NORMAL | 2024-10-12T03:06:41.399462+00:00 | 2024-10-12T09:55:33.426987+00:00 | 365 | 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)$$ -->\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $... | 2 | 0 | ['Greedy', 'Sorting', 'Python', 'C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | Easy to understand ✅✅✅| nlog(n) time complexity💯🫡 | cpp👑🎯 | easy-to-understand-nlogn-time-complexity-54on | \n\n\n# Code\ncpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n vector<pair<int, int>> events;\n for (auto& | ritik6g | NORMAL | 2024-10-12T00:05:09.883852+00:00 | 2024-10-12T00:05:09.883873+00:00 | 222 | false | \n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n vector<pair<int, int>> events;\n for (auto& interva... | 2 | 0 | ['C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | [Java] ✅99% ✅ LINE SWEEP ✅ CLEAN CODE ✅ CLEAR EXPLANATIONS | java-99-line-sweep-clean-code-clear-expl-vwa9 | Approach\n1. Use two arrays: start[1_000_001] and stop[1_000_001]\n2. For each interval, mark beginning and end on start[begin_interval]++ and stop[end_interval | StefanelStan | NORMAL | 2024-01-27T18:29:16.696042+00:00 | 2024-01-27T18:29:16.696065+00:00 | 109 | false | # Approach\n1. Use two arrays: start[1_000_001] and stop[1_000_001]\n2. For each interval, mark beginning and end on start[begin_interval]++ and stop[end_interval]++ \n3. Traverse start & stop and keep track of how many active intervals you have\n - increment activeIntervals by start[i]\n - set maxActiveIntervals... | 2 | 0 | ['Line Sweep', 'Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | JAVA solution | java-solution-by-21arka2002-suo2 | \n# Code\n\nclass Solution {\n public int minGroups(int[][] intervals) {\n Arrays.sort(intervals,(a,b)->\n {\n if(a[0]==b[0])return | 21Arka2002 | NORMAL | 2023-04-03T08:09:01.208883+00:00 | 2023-04-03T08:09:01.208911+00:00 | 442 | false | \n# Code\n```\nclass Solution {\n public int minGroups(int[][] intervals) {\n Arrays.sort(intervals,(a,b)->\n {\n if(a[0]==b[0])return a[1]-b[1];\n else return a[0]-b[0];\n });\n PriorityQueue<Integer>pq=new PriorityQueue<>();\n for(int i=0;i<intervals.length;... | 2 | 0 | ['Array', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | Line Sweep | Map | C++ | line-sweep-map-c-by-tusharbhart-cr9h | \nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n map<int, int> m;\n for(auto i : intervals) {\n m[i[0 | TusharBhart | NORMAL | 2023-02-28T14:16:39.805753+00:00 | 2023-02-28T14:16:39.805800+00:00 | 102 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n map<int, int> m;\n for(auto i : intervals) {\n m[i[0]]++;\n m[i[1] + 1]--;\n }\n int ans = 0, s = 0;\n for(auto i : m) {\n s += i.second;\n ans = max(ans, ... | 2 | 0 | ['Ordered Map', 'Line Sweep', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | Java solution nlogn | java-solution-nlogn-by-skyhuangxy-jk08 | build a timeline, order by time with start point at fromt. Then, count how many intervals are opend. If there are 3 open intervals, it means there are three ove | skyhuangxy | NORMAL | 2022-11-22T07:07:57.706377+00:00 | 2022-11-22T07:09:41.821772+00:00 | 398 | false | build a timeline, order by time with start point at fromt. Then, count how many intervals are opend. If there are 3 open intervals, it means there are three overlap parts which allow the sequence to split into three groups. \n\nSame intuition as Meeting Room II.\n\n# Complexity\n- Time complexity: nlogn\n<!-- Add your ... | 2 | 0 | ['Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++ Min Heap soln | c-min-heap-soln-by-sting285-kpsn | \nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n priority_queue<int, | Sting285 | NORMAL | 2022-11-01T16:54:15.093090+00:00 | 2022-11-01T16:54:15.093131+00:00 | 806 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n priority_queue<int, vector<int>, greater<int>>pq;\n int res = 0;\n \n for(int i=0;i<intervals.size();i++){\n if(pq.size() == 0){\n ... | 2 | 0 | ['C', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | C++ || Hashmap || start++ || end-- || Short & Clean Code | c-hashmap-start-end-short-clean-code-by-c16ew | <~ Upvote if this post is helpful\n\nApproach :\nSo the answer for the problem is maximum number of intervals that overlap, as we need to put them in separate g | Harsh_0903 | NORMAL | 2022-10-09T10:03:18.746424+00:00 | 2022-10-09T10:03:18.746465+00:00 | 206 | false | <~ **Upvote** if this post is helpful\n\nApproach :\nSo the answer for the problem is maximum number of intervals that overlap, as we need to put them in separate groups. Now, in our approach we are using a ordered map \n* incrementing the count of start of any interval , which represents a new interval is started\n* a... | 2 | 1 | [] | 0 |
divide-intervals-into-minimum-number-of-groups | ✅ [Rust] 55ms, fastest solution (100%) with BinaryHeap (with detailed comments) | rust-55ms-fastest-solution-100-with-bina-2ca9 | This solution employs BinaryHeap for the quick access to the minimal of groups\' end times. It demonstrated 55 ms runtime (100.00%) and used 8.9 MB memory (100. | stanislav-iablokov | NORMAL | 2022-09-11T18:37:43.794582+00:00 | 2022-10-23T12:57:56.846042+00:00 | 74 | false | This [solution](https://leetcode.com/submissions/detail/797349032/) employs BinaryHeap for the quick access to the minimal of groups\' end times. It demonstrated **55 ms runtime (100.00%)** and used **8.9 MB memory (100.00%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\nuse s... | 2 | 0 | ['Rust'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++ | Line Sweep | Related Problems | c-line-sweep-related-problems-by-kiranpa-m9qp | Use Line Sweep\n- Return the maximum element in the entire range.\ncpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n\n | kiranpalsingh1806 | NORMAL | 2022-09-11T10:31:22.610278+00:00 | 2022-09-11T10:31:22.610326+00:00 | 253 | false | - Use Line Sweep\n- Return the maximum element in the entire range.\n```cpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n\n int line[1000005] = {};\n int maxEle = -1;\n\n for(auto &e : intervals) {\n int start = e[0], end = e[1];\n line[star... | 2 | 0 | ['C', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++| Prefix-Sum | c-prefix-sum-by-kumarabhi98-sl3a | Hint: find the Max no.s of interval overlapping at any point\n\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& nums) {\n map<int,int> | kumarabhi98 | NORMAL | 2022-09-11T10:11:45.368706+00:00 | 2022-09-11T10:11:45.368747+00:00 | 120 | false | `Hint: find the Max no.s of interval overlapping at any point`\n```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& nums) {\n map<int,int> mp;\n for(int i = 0; i<nums.size();++i){\n mp[nums[i][0]]++; mp[nums[i][1]+1]--;\n }\n int re = 0, sum = 0;\n for(au... | 2 | 0 | ['C'] | 2 |
divide-intervals-into-minimum-number-of-groups | C++ || Multiset || Easy Solution | c-multiset-easy-solution-by-manavmajithi-n199 | \nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& arr) {\n multiset<int> m;\n int n = arr.size();\n sort(arr.begin(),arr. | manavmajithia6 | NORMAL | 2022-09-11T06:21:30.276918+00:00 | 2022-09-11T06:21:30.276954+00:00 | 61 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& arr) {\n multiset<int> m;\n int n = arr.size();\n sort(arr.begin(),arr.end());\n m.insert(arr[0][1]);\n for(int i = 1;i < n;i++){\n auto it = m.lower_bound(arr[i][0]); // checking if any end range has va... | 2 | 0 | ['C', 'C++'] | 1 |
divide-intervals-into-minimum-number-of-groups | Sorting and Min Heap Solution | sorting-and-min-heap-solution-by-travanj-s9qi | cpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>> &intervals) {\n sort(intervals.begin(), intervals.end());\n priority_queue<i | travanj05 | NORMAL | 2022-09-11T06:02:08.353592+00:00 | 2022-09-11T06:02:08.353632+00:00 | 54 | false | ```cpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>> &intervals) {\n sort(intervals.begin(), intervals.end());\n priority_queue<int, vector<int>, greater<int>> pq; // Min Heap\n int res = 0;\n for (const vector<int> &interval : intervals) {\n int start = interv... | 2 | 0 | ['Sorting', 'Heap (Priority Queue)'] | 1 |
divide-intervals-into-minimum-number-of-groups | javascript sweep line 1007ms + greedy with PQ 541ms two solutions | javascript-sweep-line-1007ms-greedy-with-7d6w | Solution 1: sweep line + 1 -1\n\nconst minGroups = (a) => sweepLineIntervals(a)\n\nconst sweepLineIntervals = (a) => {\n let d = [], h = 0, res = 0;\n fo | henrychen222 | NORMAL | 2022-09-11T04:37:48.305155+00:00 | 2022-09-11T07:02:54.954178+00:00 | 214 | false | Solution 1: sweep line + 1 -1\n```\nconst minGroups = (a) => sweepLineIntervals(a)\n\nconst sweepLineIntervals = (a) => {\n let d = [], h = 0, res = 0;\n for (const [l, r] of a) {\n d.push([l, 1]);\n d.push([r + 1, -1]);\n }\n d.sort((x, y) => {\n if (x[0] != y[0]) return x[0] - y[0];\... | 2 | 0 | ['Sorting', 'Heap (Priority Queue)', 'JavaScript'] | 1 |
divide-intervals-into-minimum-number-of-groups | [JavaScript] similar to LC253 meeting rooms - sort start and end time | javascript-similar-to-lc253-meeting-room-lay5 | https://leetcode.com/problems/meeting-rooms-ii/\n\n\nvar minGroups = function(intervals) {\n const starts = intervals.map((el) => el[0]).sort((a, b) => a - | jialihan | NORMAL | 2022-09-11T04:30:39.566282+00:00 | 2022-09-11T04:30:39.566316+00:00 | 124 | false | https://leetcode.com/problems/meeting-rooms-ii/\n\n```\nvar minGroups = function(intervals) {\n const starts = intervals.map((el) => el[0]).sort((a, b) => a - b);\n const ends = intervals.map((el) => el[1]).sort((a, b) => a - b);\n let room = 0;\n let endIdx = 0;\n for (i = 0; i < starts.length; ... | 2 | 0 | ['JavaScript'] | 1 |
divide-intervals-into-minimum-number-of-groups | Rust | BinaryHeap | With Comments | rust-binaryheap-with-comments-by-wallice-qc8x | This is my unrevised submission for the 2022-09-11 Weekly Contest 310. Sort the intervals by ascending starting time (using time here because it\'s easier to co | wallicent | NORMAL | 2022-09-11T04:19:30.416647+00:00 | 2022-09-11T04:19:30.416681+00:00 | 68 | false | This is my unrevised submission for the 2022-09-11 Weekly Contest 310. Sort the intervals by ascending starting time (using time here because it\'s easier to conceptualize maybe) followed by ascending end time. We keep a min heap / priority queue with ending times, so that we can know the soonest end time available. Fo... | 2 | 0 | ['Rust'] | 0 |
divide-intervals-into-minimum-number-of-groups | Line sweep | python | O(10^6) | Similar to shifting letters ii | line-sweep-python-o106-similar-to-shifti-dacp | similar problem: https://leetcode.com/problems/shifting-letters-ii/\t\n\n\t\tn = 1000001\n prefix = [0]*(n+1)\n for i,j in a: \n prefix | NaveenprasanthSA | NORMAL | 2022-09-11T04:13:26.897759+00:00 | 2022-09-11T04:14:36.540588+00:00 | 254 | false | similar problem: https://leetcode.com/problems/shifting-letters-ii/\t\n\n\t\tn = 1000001\n prefix = [0]*(n+1)\n for i,j in a: \n prefix[i]+=1 \n prefix[j+1]-=1 \n cursum = 0\n res = 0\n for i in prefix:\n cursum+=i\n res = max(res,cursum)\n ... | 2 | 0 | ['Python'] | 3 |
divide-intervals-into-minimum-number-of-groups | C# || Priority Queue | c-priority-queue-by-cdev-e528 | Method 1: Priority Queue\n\n public int MinGroups(int[][] intervals) \n {\n Array.Sort(intervals, (a, b) => a[0].CompareTo(b[0]));\n Priorit | CDev | NORMAL | 2022-09-11T04:07:36.729423+00:00 | 2022-09-11T21:34:12.368742+00:00 | 45 | false | **Method 1: Priority Queue**\n```\n public int MinGroups(int[][] intervals) \n {\n Array.Sort(intervals, (a, b) => a[0].CompareTo(b[0]));\n PriorityQueue<int, int> pq = new PriorityQueue<int, int>();\n int max = 0;\n foreach (int[] interval in intervals)\n {\n while (... | 2 | 0 | [] | 1 |
divide-intervals-into-minimum-number-of-groups | Simplest Way | without set and priority queue | Easy Understanding | CPP | simplest-way-without-set-and-priority-qu-9x0w | Same as Minimum Platforms Required Problem\n \n\nint minGroups(vector<vector<int>>& intervals)\n {\n vector<int> a;\n vector<int> b;\n \ | rajat0206 | NORMAL | 2022-09-11T04:06:24.992089+00:00 | 2022-09-11T04:12:01.413960+00:00 | 111 | false | Same as Minimum Platforms Required Problem\n \n```\nint minGroups(vector<vector<int>>& intervals)\n {\n vector<int> a;\n vector<int> b;\n \n for(auto &ele : intervals)\n {\n a.push_back(ele[0]);\n b.push_back(ele[1]);\n }\n \n sort(a.begin... | 2 | 1 | ['C', 'Sorting', 'C++'] | 0 |
divide-intervals-into-minimum-number-of-groups | [Python] Heap Solution | python-heap-solution-by-coldgingerale-wz6d | \nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort()\n groups = []\n \n for interval in | coldgingerale | NORMAL | 2022-09-11T04:03:40.037252+00:00 | 2022-09-11T04:07:55.057108+00:00 | 107 | false | ```\nclass Solution:\n def minGroups(self, intervals: List[List[int]]) -> int:\n intervals.sort()\n groups = []\n \n for interval in intervals:\n start, end = interval\n if groups and groups[0] < start:\n heappop(groups)\n heappush(groups, e... | 2 | 1 | [] | 2 |
divide-intervals-into-minimum-number-of-groups | JAVA Priority Queue | java-priority-queue-by-pgthebigshot-jkyv | Here if(max>=a[0]&&pq.peek()>=a[0]) checking if the total max i.e max of all right interval is greater then a[0] or not and the min value of all right interval | pgthebigshot | NORMAL | 2022-09-11T04:01:53.162516+00:00 | 2022-09-11T04:01:53.162554+00:00 | 258 | false | Here if(max>=a[0]&&pq.peek()>=a[0]) checking if the total max i.e max of all right interval is greater then a[0] or not and the min value of all right interval is greater then a[0] or not if both condition gets true then we are adding a group\n\n````\nclass Solution {\n public int minGroups(int[][] intervals) {\n ... | 2 | 0 | ['Heap (Priority Queue)'] | 2 |
divide-intervals-into-minimum-number-of-groups | Similar as "253. Meeting Rooms II" ✅ ✅ Python | similar-as-253-meeting-rooms-ii-python-b-lnqv | \n # similar as "253. Meeting Rooms II", the only difference is the definition of "intersect"\n def minGroups(self, intervals):\n """\n :typ | ufoaixam | NORMAL | 2022-09-11T04:01:09.062154+00:00 | 2022-09-11T04:39:57.023263+00:00 | 368 | false | ```\n # similar as "253. Meeting Rooms II", the only difference is the definition of "intersect"\n def minGroups(self, intervals):\n """\n :type intervals: List[List[int]]\n :rtype: int\n """\n arr = []\n for s, e in intervals:\n arr.append((s, \'s\'))\n ... | 2 | 0 | ['Sorting', 'Python'] | 1 |
divide-intervals-into-minimum-number-of-groups | Minimum Number of Groups to Cover All Intervals | minimum-number-of-groups-to-cover-all-in-let0 | ✅ IntuitionThe problem is essentially about grouping overlapping intervals. If intervals overlap, they must be placed in separate groups. We need to determine t | vishwajeetwalekar037 | NORMAL | 2025-04-09T19:21:49.231956+00:00 | 2025-04-09T19:21:49.231956+00:00 | 3 | false |
### ✅ Intuition
The problem is essentially about grouping overlapping intervals. If intervals overlap, they must be placed in separate groups. We need to determine the **minimum number of such groups** required so that no intervals in the same group overlap.
---
### 🔍 Approach
1. **Separate Start and End Times**:
... | 1 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Prefix Sum', 'Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | C# | c-by-adchoudhary-meu1 | Code | adchoudhary | NORMAL | 2025-03-04T05:07:48.369504+00:00 | 2025-03-04T05:07:48.369504+00:00 | 5 | false | # Code
```csharp []
public class Solution {
public int MinGroups(int[][] intervals) {
int max = 0;//getting max range
foreach (var inter in intervals)
{
max = Math.Max(max, inter[1]);
}
int[] line = new int[max + 2];
foreach (var inter in intervals)
{
line[inter[0]]++;
line[inter[1] ... | 1 | 0 | ['C#'] | 0 |
divide-intervals-into-minimum-number-of-groups | Java | java-by-siyadhri-rnso | \n\n# Code\njava []\nclass Solution {\n public int minGroups(int[][] intervals) {\n int n = intervals.length;\n int[] start_times = new int[n]; | siyadhri | NORMAL | 2024-10-19T13:24:46.947336+00:00 | 2024-10-19T13:24:46.947373+00:00 | 2 | false | \n\n# Code\n```java []\nclass Solution {\n public int minGroups(int[][] intervals) {\n int n = intervals.length;\n int[] start_times = new int[n];\n int[] end_times = new int[n];\n\n // Extract start and end times\n for (int i = 0; i < n; i++) {\n start_times[i] = interv... | 1 | 0 | ['Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | Divide Intervals to Minimum Groups: Efficient Priority Queue Algo | divide-intervals-to-minimum-groups-effic-yz9c | Intuition\nThe idea is to use a priority queue to efficiently track the end times of the intervals and manage the groupings.\n Describe your first thoughts on h | madhusudanrathi99 | NORMAL | 2024-10-12T18:50:53.988849+00:00 | 2024-10-12T18:51:14.388197+00:00 | 15 | false | # Intuition\nThe idea is to use a priority queue to efficiently track the end times of the intervals and manage the groupings.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. **Sort the intervals**: First, we sort the `intervals` by their `left`. This allows us to process the `int... | 1 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Prefix Sum', 'C#'] | 1 |
divide-intervals-into-minimum-number-of-groups | C++ Solution | (O(n log n)) | c-solution-on-log-n-by-22bce041-xy79 | Intuition\nThe core idea is to track when intervals start and end. For each interval, we treat the start and end as events and sort them. By processing these ev | 22BCE041 | NORMAL | 2024-10-12T18:29:48.177577+00:00 | 2024-10-13T04:13:17.253804+00:00 | 3 | false | # Intuition\nThe core idea is to track when intervals start and end. For each interval, we treat the start and end as events and sort them. By processing these events in order, we can maintain a count of how many intervals are currently overlapping. The maximum number of overlapping intervals at any given point will gi... | 1 | 0 | ['Sorting', 'C++'] | 0 |
divide-intervals-into-minimum-number-of-groups | Compact Solution Using Priority Queue and Sorting | TypeScript | compact-solution-using-priority-queue-an-clit | Intuition\nCompact solution using a priority queue and sorting.\n\n# Approach\nWe first sort the interval by start time. We then initialize a priority queue, wh | BurtTheAlert | NORMAL | 2024-10-12T18:22:09.211542+00:00 | 2024-10-12T18:22:09.211571+00:00 | 16 | false | # Intuition\nCompact solution using a priority queue and sorting.\n\n# Approach\nWe first sort the interval by start time. We then initialize a priority queue, which is to represent our interval groups. Each group is represented in the queue simply by its last end time, and the priority of the queue is this end time, s... | 1 | 0 | ['Sorting', 'Heap (Priority Queue)', 'TypeScript', 'JavaScript'] | 0 |
divide-intervals-into-minimum-number-of-groups | (python) simple solution using heap - same as seat problems | python-simple-solution-using-heap-same-a-kgvw | Intuition\nThis problem is similar with Unoccupied chair problems.\n# Approach\n1.\tSort the intervals by their start times.\n2.\tUse a min-heap to track the en | saais8217 | NORMAL | 2024-10-12T17:51:11.676813+00:00 | 2024-10-12T17:51:11.676831+00:00 | 6 | false | # Intuition\nThis problem is similar with Unoccupied chair problems.\n# Approach\n1.\tSort the intervals by their start times.\n2.\tUse a min-heap to track the end times of current intervals in different groups.\n3.\tFor each interval, check if it can fit into an existing group (i.e., if its start time is after the ear... | 1 | 0 | ['Python3'] | 0 |
divide-intervals-into-minimum-number-of-groups | Java Solution | java-solution-by-aarshpriyam-z94i | 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 | aarshpriyam | NORMAL | 2024-10-12T17:01:15.558814+00:00 | 2024-10-12T17:01:15.558837+00:00 | 38 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | Easy way to divide intervals into minimum number of groups. | easy-way-to-divide-intervals-into-minimu-hekw | 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 | Narendra_Sai | NORMAL | 2024-10-12T16:11:59.565473+00:00 | 2024-10-12T16:11:59.565497+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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 0 |
divide-intervals-into-minimum-number-of-groups | Partial Sum || C++ | partial-sum-c-by-yousseffcai-3d7s | Code\ncpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n vector<int> partial(1e6 + 2);\n for (auto x : inter | yousseffcai | NORMAL | 2024-10-12T15:21:32.253007+00:00 | 2024-10-12T15:21:32.253061+00:00 | 3 | false | # Code\n```cpp []\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n vector<int> partial(1e6 + 2);\n for (auto x : intervals) {\n partial[x[0]]++;\n partial[x[1] + 1]--;\n }\n int ans = 0;\n for (int i = 1; i <= 1e6; i++) {\n ... | 1 | 0 | ['C++'] | 0 |
divide-intervals-into-minimum-number-of-groups | Optimal solution | optimal-solution-by-hdsedighi-e667 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to group intervals such that no two intervals in the same group ove | hdsedighi | NORMAL | 2024-10-12T14:38:36.991200+00:00 | 2024-10-12T14:38:36.991226+00:00 | 19 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to group intervals such that no two intervals in the same group overlap. The key idea is to realize that the number of groups required depends on the maximum number of overlapping intervals at any point in time. If mul... | 1 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Prefix Sum', 'C#'] | 1 |
divide-intervals-into-minimum-number-of-groups | JS solution O(n log n) | js-solution-on-log-n-by-22xiao-d8s6 | Intuition\n Describe your first thoughts on how to solve this problem. \nThis problem essentially boils down to finding the maximum overlap between intervals, s | 22xiao | NORMAL | 2024-10-12T13:42:09.557534+00:00 | 2024-10-12T13:42:09.557574+00:00 | 62 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem essentially boils down to finding the **maximum overlap** between intervals, since the number of groups required equals the maximum number of intervals that overlap at any point in time.\n# Approach\n<!-- Describe your approa... | 1 | 0 | ['JavaScript'] | 1 |
divide-intervals-into-minimum-number-of-groups | Easy solution without priority_queue | easy-solution-without-priority_queue-by-3gwpl | Intuition\n Describe your first thoughts on how to solve this problem. \n\nwe need to find the maximum number of overlaping groups at a give time(or value);\nti | harsh_sharawat | NORMAL | 2024-10-12T13:25:30.344243+00:00 | 2024-10-12T13:25:30.344281+00:00 | 19 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nwe need to find the maximum number of overlaping groups at a give time(or value);\ntime ranges from 1 to 1e6;\n\n# Approach\n<h2>solution without priority_queue </h2>\n<!-- Describe your approach to solving the problem. -->\ncreate a ha... | 1 | 0 | ['Hash Table', 'Prefix Sum', 'C++'] | 2 |
divide-intervals-into-minimum-number-of-groups | C# Solution for Divide Intervals Into Minimum Number of Groups Problem | c-solution-for-divide-intervals-into-min-y0zo | Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea behind this approach is to use a min-heap (priority queue) to track the end ti | Aman_Raj_Sinha | NORMAL | 2024-10-12T13:17:05.709554+00:00 | 2024-10-12T13:17:05.709578+00:00 | 79 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea behind this approach is to use a min-heap (priority queue) to track the end times of the ongoing intervals. As we process the intervals in order of their start times, we check if the current interval can reuse a group by checking... | 1 | 0 | ['C#'] | 1 |
divide-intervals-into-minimum-number-of-groups | Priority Queue 4 line easy solution | priority-queue-4-line-easy-solution-by-k-08mi | Intuition\nGreedy\n\n# Approach\nSort the array.\nStore the second ele of each interval\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO( | kanishka1 | NORMAL | 2024-10-12T13:13:06.594822+00:00 | 2024-10-12T13:13:06.594854+00:00 | 12 | false | # Intuition\nGreedy\n\n# Approach\nSort the array.\nStore the second ele of each interval\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```java []\nclass Solution {\n public int minGroups(int[][] inte) {\n PriorityQueue<Integer> pq=new PriorityQueue<>();\n Arrays... | 1 | 0 | ['Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | Java Solution for Divide Intervals Into Minimum Number of Groups Problem | java-solution-for-divide-intervals-into-nc1i0 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to group intervals such that no two intervals in the same group ove | Aman_Raj_Sinha | NORMAL | 2024-10-12T13:12:42.407566+00:00 | 2024-10-12T13:12:42.407588+00:00 | 23 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to group intervals such that no two intervals in the same group overlap. The intuition here is to treat intervals as events: each interval has a start and an end. By sorting these events and processing them in order, w... | 1 | 0 | ['Java'] | 1 |
divide-intervals-into-minimum-number-of-groups | c++ unique approach | c-unique-approach-by-shreyasurbhisinha-gjg0 | 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 | shreyasurbhisinha | NORMAL | 2024-10-12T13:00:24.703831+00:00 | 2024-10-12T13:00:24.703869+00:00 | 27 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 1 |
sliding-window-median | Java using two Tree Sets - O(n logk) | java-using-two-tree-sets-on-logk-by-kido-d02p | Inspired by this solution. to the problem: 295. Find Median from Data Stream\n\nHowever instead of using two priority queue's we use two Tree Sets as we want O( | kidoptimo | NORMAL | 2017-02-13T07:04:26.896000+00:00 | 2018-10-17T22:34:06.671364+00:00 | 38,942 | false | Inspired by this [solution](https://discuss.leetcode.com/topic/27521/short-simple-java-c-python-o-log-n-o-1). to the problem: [295. Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/)\n\nHowever instead of using two priority queue's we use two ```Tree Sets``` as we want ```O(logk)... | 329 | 14 | [] | 55 |
sliding-window-median | O(n log k) C++ using multiset and updating middle-iterator | on-log-k-c-using-multiset-and-updating-m-2bhh | Keep the window elements in a multiset and keep an iterator pointing to the middle value (to "index" k/2, to be precise). Thanks to @votrubac's solution and com | stefanpochmann | NORMAL | 2017-01-11T01:58:51.459000+00:00 | 2018-09-17T22:10:43.660085+00:00 | 52,541 | false | Keep the window elements in a multiset and keep an iterator pointing to the middle value (to "index" k/2, to be precise). Thanks to [@votrubac's solution and comments](https://discuss.leetcode.com/topic/74739/c-95-ms-single-multiset-o-n-log-n).\n\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n ... | 286 | 2 | [] | 51 |
sliding-window-median | Never create max heap in java like this... | never-create-max-heap-in-java-like-this-wu5ak | I spent 2 hours debugging my code because I couldn't pass the last test case:\n\n[-2147483648,-2147483648,2147483647,-2147483648,1,3,-2147483648,-100,8,17,22,-2 | loushengbo | NORMAL | 2017-08-16T11:30:16.378000+00:00 | 2017-08-16T11:30:16.378000+00:00 | 10,338 | false | I spent 2 hours debugging my code because I couldn't pass the last test case:\n```\n[-2147483648,-2147483648,2147483647,-2147483648,1,3,-2147483648,-100,8,17,22,-2147483648,-2147483648,2147483647,2147483647,2147483647,2147483647,-2147483648,2147483647,-2147483648]\n6\n```\nFinally, I found out why:\n\nI created my max ... | 253 | 4 | [] | 18 |
sliding-window-median | Python Small & Large Heaps | python-small-large-heaps-by-wangqiuc-rcrw | To calculate the median, we can maintain divide array into subarray equally: small and large. All elements in small are no larger than any element in large. So | wangqiuc | NORMAL | 2019-03-26T23:22:50.191770+00:00 | 2019-11-02T23:46:13.477067+00:00 | 24,395 | false | To calculate the median, we can maintain divide array into subarray equally: **small** and **large**. All elements in **small** are no larger than any element in **large**. So median would be (largest in **small** + smallest in **large**) / 2 if **small**\'s size = **large**\'s size. If large\'s size = small\'s size + ... | 230 | 5 | [] | 28 |
sliding-window-median | Solution | solution-by-deleted_user-ojse | C++ []\nclass Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> medians;\n unordere | deleted_user | NORMAL | 2023-01-05T19:30:47.085127+00:00 | 2023-03-07T08:37:35.478122+00:00 | 17,180 | false | ```C++ []\nclass Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> medians;\n unordered_map<int, int> hashTable;\n priority_queue<int> lo;\n priority_queue<int, vector<int>, greater<int>> hi;\n\n int i = 0;\n\n... | 215 | 3 | ['C++', 'Java', 'Python3'] | 6 |
sliding-window-median | Java solution using two PriorityQueues | java-solution-using-two-priorityqueues-b-it87 | Almost the same idea of Find Median from Data Stream https://leetcode.com/problems/find-median-from-data-stream/\n1. Use two Heaps to store numbers. maxHeap for | shawngao | NORMAL | 2017-01-09T03:58:50.751000+00:00 | 2018-10-19T22:51:28.799438+00:00 | 43,252 | false | Almost the same idea of ```Find Median from Data Stream``` https://leetcode.com/problems/find-median-from-data-stream/\n1. Use two ```Heaps``` to store numbers. ```maxHeap``` for numbers smaller than current median, ```minHeap``` for numbers bigger than and ```equal``` to current median. A small trick I used is always... | 141 | 10 | [] | 32 |
sliding-window-median | Python clean solution (easy to understand) | python-clean-solution-easy-to-understand-3g0t | I was confused by the official solution and many of the top posts. This problem shouldn\'t be that hard! I ended up using the same template as in Question 295 a | ziweigu | NORMAL | 2019-09-30T19:30:59.756493+00:00 | 2019-09-30T19:35:18.998710+00:00 | 10,242 | false | I was confused by the official solution and many of the top posts. This problem shouldn\'t be that hard! I ended up using the same template as in Question 295 and passed all tests on my first attempt. The key is using two heaps (just like 295) and keeping track of just two things - the element to include and the elemen... | 126 | 1 | [] | 15 |
sliding-window-median | O(n*log(n)) Time C++ Solution Using Two Heaps and a Hash Table | onlogn-time-c-solution-using-two-heaps-a-m0ek | There are a few solutions using BST with worst case time complexity O(nk), but we know k can be become large. I wanted to come up with a solution that is guaran | ipt | NORMAL | 2017-01-08T22:14:29.003000+00:00 | 2018-09-04T18:04:48.031716+00:00 | 15,981 | false | There are a few solutions using BST with worst case time complexity O(n*k), but we know k can be become large. I wanted to come up with a solution that is guaranteed to run in O(n\\*log(n)) time. This is in my opinion the best solution so far.\n\nThe idea is inspired by solutions to [Find Median from Data Stream](https... | 84 | 0 | [] | 14 |
sliding-window-median | Easy Python O(nk) | easy-python-onk-by-stefanpochmann-yjph | Just keep the window as a sorted list.\n\n def medianSlidingWindow(self, nums, k):\n window = sorted(nums[:k])\n medians = []\n for a, b | stefanpochmann | NORMAL | 2017-01-08T11:24:23.726000+00:00 | 2018-09-22T05:54:45.299505+00:00 | 16,700 | false | Just keep the window as a sorted list.\n\n def medianSlidingWindow(self, nums, k):\n window = sorted(nums[:k])\n medians = []\n for a, b in zip(nums, nums[k:] + [0]):\n medians.append((window[k/2] + window[~(k/2)]) / 2.)\n window.remove(a)\n bisect.insort(window,... | 83 | 2 | [] | 16 |
sliding-window-median | Python real O(nlogk) solution - easy to understand | python-real-onlogk-solution-easy-to-unde-ybyj | Solution 1: O(nk)\nMaitain a sorted window. We can use binary search for remove and insert. \nBecause insert takes O(k), the overall time complexity is O(nk).\ | happy_little_pig | NORMAL | 2020-08-22T22:51:35.815802+00:00 | 2023-11-24T00:53:23.587096+00:00 | 7,858 | false | **Solution 1: `O(nk)`**\nMaitain a sorted window. We can use binary search for remove and insert. \nBecause insert takes `O(k)`, the overall time complexity is `O(nk)`.\n\n**Solution 2: `O(nk)`**\nSimilar with LC 295, we need to maintain two heaps in the window, leftHq and rightHq. \nTo slide one step is actually to d... | 71 | 0 | ['Python', 'Python3'] | 14 |
sliding-window-median | ✅ Easiest Python O(n log k) Two Heaps (Lazy Removal), 96.23% | easiest-python-on-log-k-two-heaps-lazy-r-dj61 | How to understand this solution:\n1) After we build our window, the length of window will ALWAYS be the same (now we will keep the length of valid elements in m | AntonBelski | NORMAL | 2022-04-13T10:08:47.422508+00:00 | 2022-06-29T16:03:58.527334+00:00 | 8,018 | false | How to understand this solution:\n1) After we build our window, the length of window will ALWAYS be the same (now we will keep the length of valid elements in max_heap and min_heap the same too)\n2) Based on this, when we slide our window, the balance variable can be equal to 0, 2 or -2. It will NEVER be -1 or 1.\nExam... | 59 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.