← Nextdoor Interview Insights

Nextdoor·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Mar 2026Remote

Summary

Coding round for an MLE role at Nextdoor. One meaty algorithmic problem that looks like a sorting question until you realize the photo grouping logic makes it way messier than it first appears.

Questions Asked (1)

Q1

You have a list of feed objects, each with an id, score, and type (Normal, Video, or Photo). Every 3 consecutive Photo objects should be merged into a single grouped photo object whose score is the highest score among those 3 photos. After grouping, sort all objects (grouped photos included) by score in descending order. How do you handle groups with fewer than 3 consecutive photos, and how does score-based sorting interact with the grouping step?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I jumped straight to the sort and completely skipped thinking about what 'consecutive' actually means in this context.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the grouping rule for consecutive Photo objects, especially for groups of fewer than 3, and confirm whether sorting should be stable or by score alone. Then outline a two-pass algorithm: first scan and merge consecutive photos, then sort the resulting list by score descending. Discuss edge cases and trade-offs.

Pro tip: Mention that grouping must be done before sorting because the score of a grouped photo depends on the max of its members, and sorting first would break the consecutive grouping. Also, propose a stable sort to preserve original order for ties, which is often expected in feed ranking.

1. Clarify requirements and edge cases

Ask about the handling of groups with 1 or 2 consecutive photos: should they remain ungrouped or be grouped anyway? Confirm if 'consecutive' means adjacent in the original list and if grouping resets after non-photo objects.

2. Design the grouping algorithm

Iterate through the list, tracking consecutive Photo objects. When a group reaches 3, create a grouped object with max score and reset the counter. For leftover photos (1 or 2), decide to keep them as individual objects or group them as a smaller group based on clarification.

3. Sort the resulting list

After grouping, sort all objects (including grouped photos) by score in descending order. Use a stable sort to maintain original order for equal scores, ensuring deterministic output.

4. Analyze complexity and trade-offs

The grouping pass is O(n) and sorting is O(m log m) where m is the number of objects after grouping. Discuss if in-place grouping is possible or if extra space is needed, and the impact of stable sorting.

5. Test with examples

Walk through a small example to verify correctness, such as [Photo(1), Photo(2), Photo(3), Video(4), Photo(5), Photo(6)] and show the grouped and sorted output.

Key Points to Mention

  • Grouping must precede sorting because the grouped score depends on consecutive photos.
  • Handling of leftover photos (1 or 2) should be clarified; common approaches are to leave them ungrouped or group them as a smaller group.
  • Use a stable sort to preserve original order for ties, which is important for feed ranking.
  • Time complexity: O(n) for grouping and O(m log m) for sorting, where m ≤ n.
  • Space complexity: O(n) for the output list, but can be optimized if in-place grouping is allowed.
  • Edge cases: empty list, all photos, no photos, groups of exactly 3, and groups larger than 3 (e.g., 6 photos should form two groups of 3).

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