J 크 2023. 11. 27. 11:25
728x90
반응형

https://leetcode.com/problems/meeting-rooms-ii/description/

 

Meeting Rooms II - LeetCode

Can you solve this real interview question? Meeting Rooms II - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

long time no see~


※  Question Summary

▶ Input : An array of meeting time intervals (2D array where some[i] = [start(i), end(i)])

▶ Output : Return the minimum of conference rooms required


◈ Input - 1

[[0,30],[5,10],[15,20]]

◈ Output - 1

2

◈ Input - 2

[[0,30],[5,10],[15,20]]

◈ Output - 2

1

 ◎  HOW TO SOLVE IT

▶ Constraints : 1 <= intervals.length <= 10^4 && 0 <= start(i) < end(i) <= 10^6

▶ The result must be greater than 0.

▶ Make an 1Darray (size of 10^6)  for counting the meeting times

Update the count for each interval [start(i), end(i)] in the input array.

▶ Return the maximum count from the counting array


class Solution {
    public int minMeetingRooms(int[][] intervals) {
        int[] narrCounts = new int[1000000];

        int nMax = 1;
        for(int i = 0; i < intervals.length; i++) {
            for(int j = intervals[i][0]; j < intervals[i][1]; j++) {
                narrCounts[j]++;
            }
        }

        for(int i = 0; i < narrCounts.length; i++)
            nMax = Math.max(nMax, narrCounts[i]);

        return nMax;
    }
}

영어 재밌네요