Stop the Most Incoming Spam Waves Before Any Reaches the Inbox

Last updated: November 29, 2026

Quick Overview

Gmail's defense can neutralize one incoming spam wave per minute, starting at minute 0. Each wave starts at some distance and moves at a constant speed toward the inbox; return how many waves you can neutralize before any wave arrives, where a wave arriving at the same moment as the defense is ready counts as a loss.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Gmail's defense can neutralize one incoming spam wave per minute, starting at minute 0. Each wave starts at some distance and moves at a constant speed toward the inbox; return how many waves you can neutralize before any wave arrives, where a wave arriving at the same moment as the defense is ready counts as a loss.

A deadline-ordering greedy that suits a Google online assessment. The interviewer checks that you convert each wave to an arrival time, sort, and compare against the minute you would handle it, with careful rounding.

What the Interviewer Expects
  • Convert distance and speed into an arrival time
  • Sort by arrival time (earliest deadline first)
  • Compare arrival with the minute index
  • Use integer ceiling to avoid floating point
  • O(n log n) time
Key Topics to Cover
Greedy
Earliest deadline first
Sorting
Integer math
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • The defense recharges every r minutes instead of every minute.
  • Two defenses fire in parallel.
  • Waves can be slowed instead of stopped.
  • Do it in O(n) using counting since arrival times are bounded by n.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: lists dist and speed (positive ints). At minute i (0, 1, 2, ...) you neutralize one wave. A wave reaching distance 0 at time t beats you if t <= i for the minute i when you would ha...

High-Level Design

Each wave has a deadline: its arrival time dist / speed. With one action per minute, the classic earliest-deadline-first rule is optimal: handle the most urgent wave first. Swapping two waves out of...


Submit Your Answer
Markdown supported