Two City Scheduling
Solve LeetCode #1029, “Two City Scheduling.” Read the official prompt once, then return here to turn its requirements into the greedy algorithms pattern.
Open official problem prompt ↗Learn how to translate “Two City Scheduling” into a precise state, transition, and stopping condition before committing to code.
Treat the prompt like a route on a map: Greedy Algorithms is the map legend, the invariant is your current location marker, and each code step must move you closer to the destination without losing what is already known.
- Input
- Use the first example in the official prompt
- Output
- Predict the result before reading the explanation
- Why
- Trace how the greedy algorithms invariant transforms the input into the required answer.
Identify the input shape and required return valueMark the largest constraint before choosing an approachConfirm that O(n log n) is appropriate for that constraint