Divide Intervals Into Minimum Number of Groups | Leetcode 2406

preview_player
Показать описание
This video explains Divide Intervals Into Minimum Number of Groups using line sweep 1D and difference array techniques. These are 2 optimal techniques for the problem depending on input constraints.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

Some channels are focusing on how to solve the given problem
But you focusing on concept which can be applied for many problem robustly
Thankyou so much sir❤❤

berry
Автор

using 1st approach
testcase - [1, 1]
[[1, 1], [1, -1]]
sort karte time [1, -1] phele aata hai toh overlap= -1 after that overlap 0, ans =1
testcase fail hora hai

AryanJain-hjni
Автор

How does test case [[1, 5], [2, 5]] suffice here, answer from max overlap thing should be 3 while only 2 groups can be formed? Am I missing something here? Also not sure how can someone think towards intuition of max overlap when solving this for the first time, video also doesn't explains that....(Editing) Watched the second half and this test case is solvable from the second approach tho : 0, 1, 1, 0, 0, 0, -2. overlap: 0, max_overlap: 2. But naming this as overlap is entirely wrong, gives wrong idea. How was overlap variable in second approach of any use, when we are only considering variable max_overlap for our answer?

mridulsetia
Автор

Sir can you start a new playlist on leetcode 150. apart from this daily videos. that would be incediblly helpful.
also can you make a border techdose problem list. i have almost solved Techdose100 already.

BananaButcher
Автор

could you please check, its not working
class Solution {
public int minGroups(int[][] intervals) {
class Point implements Comparable<Point> {
int index;
int type;

Point(int a, int b) {
index = a;
type = b;
}

public String toString() {
return "{" + index + ", " + type + "}";
}

public int compareTo(Point p) {
if (index == p.index)
return 0;
if (index < p.index)
return -1;
return 1;

}
}
List<Point> points = new ArrayList<>();
for (int i = 0; i < intervals.length; i++) {
points.add(new Point(intervals[i][0], 1));
points.add(new Point(intervals[i][1] + 1, -1));
}
Collections.sort(points);
int overlap = 0, max_overlap = 0;
for (Point point : points) {
if (point.type == 1) {
overlap++;
} else {
overlap--;
}
max_overlap = Math.max(max_overlap, overlap);
}
return max_overlap;
}
}

rahulkumar