← Amazon Interview Insights

Amazon·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Amazon OA for a SWE role. One algorithmic problem, classic weighted interval scheduling dressed up in a streaming/theater theme. Nothing too wild but the problem has a few edge cases that can trip you up if you're not careful.

Questions Asked (1)

Q1

Given a list of screenings each with a start time, duration, and audience size, find the maximum total audience you can achieve by selecting non-overlapping screenings.

Algorithms & Data Structures
Author's notes

Weighted interval scheduling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a weighted interval scheduling problem where we maximize total audience instead of count. Sort screenings by end time, then use dynamic programming: for each screening, either skip it or take it plus the best non-overlapping schedule before its start. Precompute the latest non-overlapping screening via binary search to achieve O(n log n) time.

Pro tip: Clarify whether screenings that touch at endpoints (end time equals start time) are considered overlapping; state your assumption and handle it consistently. Also, mention that if all audiences were 1, this reduces to the classic activity selection problem, showing you recognize the generalization.

1. Clarify and Define

Confirm input format, whether times are integers or floats, and if back-to-back screenings are allowed. Define the objective: maximize sum of audience sizes of selected non-overlapping screenings.

2. Sort and Precompute

Sort screenings by end time. For each screening i, use binary search to find p(i), the largest index j < i such that screening j ends before screening i starts (or at the same time if allowed).

3. Define DP Recurrence

Let dp[i] be the max audience using screenings 1..i. Recurrence: dp[i] = max(dp[i-1], audience[i] + dp[p(i)]). Base case dp[0] = 0.

4. Compute and Reconstruct

Iterate i from 1 to n to fill dp. Optionally, backtrack to list selected screenings. Return dp[n] as the maximum total audience.

5. Analyze Complexity

Sorting takes O(n log n), binary search per screening O(log n), DP O(n). Overall O(n log n) time and O(n) space. Mention that a greedy approach fails because audiences are weights.

Key Points to Mention

  • Weighted interval scheduling is a dynamic programming problem, not solvable by simple greedy (e.g., earliest finish time) when weights vary.
  • Sorting by end time enables efficient computation of the latest non-overlapping predecessor via binary search.
  • DP state: dp[i] = max audience considering first i screenings (sorted by end time).
  • Recurrence: dp[i] = max(dp[i-1], audience[i] + dp[p(i)]), where p(i) is the latest compatible screening index.
  • Time complexity O(n log n) due to sorting and binary search; space O(n) for DP array.
  • Edge cases: empty list, single screening, all overlapping, zero durations, and tie-breaking in sorting.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.