FastPrepAdd Course Batches All or Nothing
Problems/Add Course Batches All or Nothing

Add Course Batches All or Nothing

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Dec 2026

QuestionExamples

Problem statement

Source note: Reported in an Amazon interview for a Software Development Engineer 2 (L5) role in India. It was the first of four interview rounds after the online assessment, a coding round that also had leadership questions. The report describes a twist on the classic prerequisite-ordering problem: decide whether a group of new courses can join an existing set of courses, and add either the whole group or nothing. The candidate first treated it as the plain ordering problem.

The report gives no input format, return shape, examples or limits. The limits are our own choice, and so are the row format (a course followed by its prerequisites), the list of batches with one true or false per batch, and the rule that a batch is rejected when it repeats a course already in the schedule or names a prerequisite that does not exist. All examples are our own.

Our version is about 80% the same as the reported question.

A school keeps a schedule of courses. A course may have prerequisites: other courses that must also be in the schedule. You are given the current schedule existing and a list of batches of new courses batches. Go through the batches in order and decide for each one whether it can be added.

Courses are written as rows. A row [c, p1, p2, ...] describes course c with prerequisites p1, p2, ..., and a row [c] is a course with no prerequisites. existing is a list of rows, and each batch batches[j] is a list of rows too.

The problem statement continues
Pro

Examples

Example 1

existing = [[0],[1,0],[2,1]]batches = [[[3,2],[4,3,0]],[[5,6],[6,5]],[[5,4],[6,7]],[[5,4],[6,5]]]return = [true,false,false,true]

The schedule starts with courses 0, 1 and 2. Batch 0: course 3 needs 2, which is in the schedule, and course 4 needs 3 (in the same batch) and 0 (in the schedule), so the batch is added. Batch 1: course 5 needs 6 and course 6 needs 5, so neither can come first, and the batch is rejected. Batch 2: course 6 needs 7, which is neither in the schedule nor in the batch, so the batch is rejected, and course 5 is not added either, even though its prerequisite 4 is in the schedule. Batch 3: course 5 needs 4, in the schedule since batch 0, and course 6 needs 5, in the same batch, so the batch is added. The schedule ends with courses 0 to 6.

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Amazon Onsite Interview questions

  • Priority Ad Rotation with Show LimitsONSITE INTERVIEW · Seen Dec 2026
  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Flood FillONSITE INTERVIEW · Seen Nov 2026
  • Merge k Sorted ListsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Package Install OrderVerily · ONSITE INTERVIEW
  • Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Validate CSV References and Field DependenciesStripe · PHONE SCREENStripe interview questions
  • Recipes You Can PrepareIndeed · PHONE SCREENIndeed interview questions
  • Data Pipeline Steps with Search and Run OrderRippling · PHONE SCREENRippling interview questions
  • Propagate Spreadsheet Cell UpdatesOpenAI · PHONE SCREENOpenAI interview questions
  • Lexicographically Smallest Topological OrderCoinbase · PHONE SCREENCoinbase interview questions

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week