Detect Port Scans From Streaming Flow Records

Last updated: November 29, 2026

Quick Overview

Given flow records sorted by timestamp as (ts, source, destination, port), flag each source the first time it contacts at least k distinct (destination, port) targets within any sliding window of W seconds, and report the timestamp at which it was flagged.

Illumio
Coding & Algorithms
Software Engineer
Illumio
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given flow records sorted by timestamp as (ts, source, destination, port), flag each source the first time it contacts at least k distinct (destination, port) targets within any sliding window of W seconds, and report the timestamp at which it was flagged.

Reconnaissance is the first stage of lateral movement, and VEN flow telemetry is exactly the data Illumio's detection features see. The interviewer looks for a correct sliding window with a distinct count, not a recount per event, and clear window boundary semantics.

What the Interviewer Expects
  • Keeps a per-source deque of events plus a count of each target inside the window
  • Evicts expired events before checking the threshold
  • Counts distinct targets, so repeated hits on one port do not trigger
  • Stops tracking a source once flagged
  • States amortized O(1) work per record
Key Topics to Cover
Sliding window
Hash maps
Streaming detection
Lateral movement
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
  • Distinguish a vertical scan (many ports, one host) from a horizontal sweep (one port, many hosts).
  • Records arrive slightly out of order, up to 5 seconds late. How do you adapt?
  • How would you shard this across many stream processors?
  • How would you suppress known scanners such as vulnerability management hosts?
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

Window semantics: at time ts, the window holds events with timestamp greater than ts - W. A target is a (dst, port) pair. A source is flagged once, at the first record where its distinct target ...

High-Level Design

Per source, keep a deque of (ts, target) and a dictionary from target to how many times it appears in the deque. On each record, append, increment, then pop from the left while the oldest event is o...


Submit Your Answer
Markdown supported

Related Questions