Data Structures & AlgorithmsHardProduct Company SDE · CAT · MBA placement
Problem: Maximum number of non-overlapping meetings that can be held in one room, where a meeting is an interval [start, end) and two meetings may touch at an endpoint. The intervals are [1,4), [3,5), [0,6), [5,7), [3,9), [5,9), [6,10), [8,11), [8,12), [2,14), [12,16). What is the maximum?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
The earliest-finishing greedy rule is optimal for interval scheduling. Sorting by start time instead of end time can give a wrong count.
More Coding Interview Problems questions
- Problem: How many contiguous subarrays of [3, -1, 4, -2, 5, -6, 2, 1] have sum at most 6 when the sum is computed over all non-empty…
- Problem: Longest substring without repeating characters of "pwwkewabcdbbxq". What is its length?
- Problem: Build a binary search tree by inserting 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 in that order (duplicates are not inserted). Count…
- Problem: Starting from an empty tree of directed edges, a DAG has edges 0→1, 0→2, 1→3, 2→3, 2→4, 3→5, 4→5, 1→4. How many distinct directed…
- Problem: An MST is built with Kruskal's algorithm on vertices 0–4 and edges: 0-1 (4), 0-2 (1), 1-2 (2), 1-3 (5), 2-3 (8), 3-4 (3), 2-4…
- Problem: How many pairs (i, j) with i < j in the array [4, 8, 1, 5, 9, 2, 7, 3, 6] satisfy a[j] − a[i] = 3?