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

0% completed

Vote For New Content
Em Eff
Queue-based approach in JS

Em Eff

Mar 27, 2025

With what looks like possible non-heap solutions posted, I'm not sure why the official solution uses one.

Here's a solution that leverages a Queue (or an array for simplicity's sake.) It basically just removes all meetings that start before the current then, after adding the current meeting to the queue, counts the max number rooms in use at any given time.

class Solution { findMinimumMeetingRooms(meetings) { let minRooms = 0 meetings = meetings.sort((a, b) => a.start - b.start) const queue = [] for(let meeting of meetings) { while(queue.length && queue[0].end <= meeting.start) { queue.shift() } queue.push(meeting) minRooms = Math.max(minRooms, queue.length) } return minRooms } }

0

1

Comments
Comments

On this page