THN Interview Prep

252. Meeting Rooms

At a Glance

  • Topic: intervals
  • Pattern: Merge Intervals (sort + pairwise check)
  • Difficulty: Easy
  • Companies: Amazon, Google, Facebook, Microsoft, Bloomberg
  • Frequency: High
  • LeetCode: 252

Problem (one-liner)

Given meeting intervals [start, end], determine whether one person could attend all meetings (no overlaps). Input: intervals. Output: boolean.

Core Basics

  • Opening move: classify the object (interval, multiset, trie node, bitmask, overlapping sub-intervals…) and whether the answer lives in an enumeration, ordering, partition, graph walk, DP table, etc.
  • Contracts: spell what a valid partial solution looks like at each step—the thing you inductively preserve.
  • Complexity anchors: state the brute upper bound and the structural fact (sorting, monotonicity, optimal substructure, greedy exchange, hashability) that should beat it.

Understanding

  • Why brute hurts: name the repeated work or state explosion in one sentence.
  • Why optimal is safe: the invariant / exchange argument / optimal-subproblem story you would tell a staff engineer.

Memory Hooks

  • One chant / rule: a single memorable handle (acronym, operator trick, or shape) you can recall under time pressure.

Recognition Cues

  • “Can attend all” → no overlap between consecutive meetings after sorting by start
  • Sort by start time, verify next.start >= previous.end (strictly >= for touching ok depending on statement—usually adjacent allowed)

Study Pattern (SDE3+)

  • 0–3 min: restate I/O and brittle edges aloud, then verbalize two approaches with time/space before you touch the keyboard.
  • Implementation pass: one-line invariant above the tight loop; state what progress you make each iteration.
  • 5 min extension: pick one constraint twist (immutable input, stream, bounded memory, parallel readers) and explain what in your solution breaks without a refactor.

Diagram

At-a-glance flow (replace with problem-specific Mermaid as you refine this note). camelCase node IDs; no spaces in IDs.

Loading diagram…

Approaches

  • Check all pairsO(n²) time.
  • Sort + linear scanO(n log n) time / O(1) extra. <- pick this in interview.

Optimal Solution

Go

package main

import "sort"

func canAttendMeetings(intervals [][]int) bool {
	if len(intervals) <= 1 {
		return true
	}
	sort.Slice(intervals, func(left int, right int) bool {
		return intervals[left][0] < intervals[right][0]
	})
	for index := 1; index < len(intervals); index++ {
		previousEnd := intervals[index-1][1]
		currentStart := intervals[index][0]
		if currentStart < previousEnd {
			return false
		}
	}
	return true
}

JavaScript

function canAttendMeetings(intervals) {
	if (intervals.length <= 1) return true;
	const sorted = [...intervals].sort((left, right) => left[0] - right[0]);
	for (let index = 1; index < sorted.length; index++) {
		const previousEnd = sorted[index - 1][1];
		const currentStart = sorted[index][0];
		if (currentStart < previousEnd) return false;
	}
	return true;
}

Walkthrough

[[0,30],[5,10],[15,20]] → after sort by start, overlap between [0,30] and [5,10]false.

Invariant: sorted by start, only adjacent checks matter for conflicts.

Edge Cases

  • Empty list → true
  • Touching meetings [1,2],[2,3] → typically true with < test

Pitfalls

  • Using <= boundary wrong for inclusive/exclusive end conventions

Similar Problems

Variants

  • Minimum rooms → Meeting Rooms II.

Mind-Map Tags

#intervals #sort #overlap-check #easy

Mark this page when you finish learning it.

Last updated on

Spotted something unclear or wrong on this page?

On this page