This one took me a minute to even parse what 'two consecutive years' meant in context.
Use a sweep line algorithm: create events for each class's start and end years, sort them, and track the number of students over time. For each pair of consecutive years, compute the sum of students from classes that span both years, and keep the maximum.
Pro tip: Clarify whether the years are inclusive and whether classes with zero size count. Also, consider if the list is large and if we can optimize by only checking years where changes occur.
Ask if start and end years are inclusive, if classes can have zero size, and if the list is sorted. Confirm that 'consecutive years' means two years in a row (e.g., 2020 and 2021).
Decide between a sweep line with events or a difference array if the year range is small. For large ranges, use a sorted list of events.
For each class, create a start event (+size) at start year and an end event (-size) at end year + 1 (if inclusive). Sort events by year and sweep, maintaining current total students.
During the sweep, for each year, record the total students. Then iterate through consecutive years and compute the sum of students for each pair, tracking the maximum.
Consider empty list, classes with same start and end year, and years with no classes. Ensure the algorithm returns 0 if no students.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.