Blind 75
Meeting Rooms
- Problem
- LC 252
- Category
- Interval
- File
- blind75_LC252MeetingRooms.java
- Path
- pkg5leetcode/blind75/blind75_LC252MeetingRooms.java
- Package
- pkg5leetcode.blind75
- Command
- java pkg5leetcode/blind75/blind75_LC252MeetingRooms.java
- Approach
- Sort by start; check no overlap between consecutive.
- Complexity
- Time O(n log n), Space O(1)
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg5leetcode.blind75;2 3/*4 * Meeting Rooms | LC 2525 * APPROACH: Sort by start; check no overlap between consecutive.6 * COMPLEXITY: Time O(n log n), Space O(1)7 */8import java.util.*;9 10public class blind75_LC252MeetingRooms {11 static boolean canAttendMeetings(int[][] intervals) {12 Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0]));13 for (int i = 1; i < intervals.length; i++)14 if (intervals[i][0] < intervals[i - 1][1]) return false;15 return true;16 }17 18 public static void main(String[] args) {19 check(!canAttendMeetings(new int[][]{{0, 30}, {5, 10}, {15, 20}}), "case1");20 check(canAttendMeetings(new int[][]{{7, 10}, {2, 4}}), "case2");21 System.out.println("all tests passed");22 }23 24 static void check(boolean cond, String name) {25 if (!cond) throw new AssertionError("FAILED: " + name);26 System.out.println(" PASS " + name);27 }28}