Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Why change up the style of the answer in such a drastic way vs eariler? It only ...

CaptainKidd

Feb 5, 2023

Why change up the style of the answer in such a drastic way vs eariler? It only adds to confusion with no benefit.

Here's something similar to the examples we've seen this far. Please note similarity in structure to sliding window.

Arrays.sort(intervals, (a,b)->Integer.compare(a[0], b[0])); PriorityQueue minHeap = new PriorityQueue(intervals.length, (a, b) -> Integer.compare(a[1], b[1])); int minRooms = 0; for(int[] interval : intervals){ if(!minHeap.isEmpty() && interval[0]>=minHeap.peek()[1]){ minHeap.poll(); } minHeap.offer(interval); minRooms = Math.max(minHeap.size(), minRooms); } return minRooms;

0

0

Comments
Comments

On this page