← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding question, just one problem about finding the class with the most students across two consecutive years. Pretty focused session, nothing behavioral from what I can tell.

Questions Asked (1)

Q1

You're given a list of classes, each with a name, size, start year, and end year. Find the maximum number of students attending across any two consecutive years.

Algorithms & Data Structures
Author's notes

This one took me a minute to even parse what 'two consecutive years' meant in context.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Clarify assumptions

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).

2. Choose data structure

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.

3. Process 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.

4. Compute consecutive sums

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.

5. Handle edge cases

Consider empty list, classes with same start and end year, and years with no classes. Ensure the algorithm returns 0 if no students.

Key Points to Mention

  • Sweep line algorithm with events for start and end years
  • Time complexity: O(n log n) due to sorting events, space O(n)
  • Inclusive vs exclusive year ranges and how to adjust end events
  • Using a difference array if year range is bounded
  • Handling overlapping classes and summing sizes
  • Edge cases: empty input, zero-size classes, single-year classes

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