← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snapchat software engineer interview with a sliding window problem that looked manageable until it really wasn't. The median part is what gets you.

Questions Asked (1)

Q1

Given an array of numbers and a window size k, compute the median of each window as it slides from left to right across the array.

Algorithms & Data Structures
Author's notes

I knew what a sliding window was, sure, but maintaining a running median as elements enter and leave the window is a completely different problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., array size, k, data types) and then discuss the brute-force approach (O(n*k log k)) before optimizing with a data structure that supports efficient insertion, deletion, and median retrieval, such as two heaps or a balanced BST. Explain the trade-offs between different approaches and finally walk through a concrete example to validate the solution.

Pro tip: Mention that for large datasets, using two heaps (max-heap for lower half, min-heap for upper half) with lazy deletion can achieve O(n log k) time, but be prepared to discuss how to handle deletions from the heaps efficiently, as that's a common follow-up.

1. Clarify requirements and constraints

Ask about input size, whether k is always valid, if the array can contain duplicates, and if the median definition for even-sized windows (average of two middle elements) is expected.

2. Discuss brute-force approach

Explain that for each window, you could sort the elements and find the median, resulting in O(n*k log k) time. This sets a baseline for optimization.

3. Propose optimized data structure

Introduce using two heaps (max-heap for lower half, min-heap for upper half) to maintain the window's elements, allowing O(log k) insertion and deletion, and O(1) median retrieval.

4. Handle sliding window operations

Describe how to add the new element and remove the oldest element from the heaps, ensuring the heaps remain balanced and the median is correctly computed after each slide.

5. Analyze complexity and edge cases

State the overall time complexity O(n log k) and space O(k). Discuss edge cases like k=1, k=n, and even/odd window sizes.

Key Points to Mention

  • Time complexity comparison: brute-force O(n*k log k) vs optimized O(n log k)
  • Use of two heaps (max-heap and min-heap) to maintain the median efficiently
  • Handling deletions from heaps, possibly with lazy deletion or a balanced BST
  • Median definition for even-sized windows: average of two middle elements
  • Edge cases: k=1, k=n, array with duplicates, negative numbers
  • Space complexity: O(k) for storing the window elements

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