As reported: Visa Software Engineer (Bangalore), round 2 — technical (May 2025): after a 30-minute project deep dive, one DSA question. It opened with what a DDoS attack is and how to prevent one; then: given a log file of timestamps and IPs, rate-limit the IPs that make more than
xrequests in a 10-minute window — a sliding-window solution. Follow-up: the log file is several GB.
A web server's log is given as two arrays of equal length: timestamps[i] (seconds) and ips[i], the IP of request i. The log is in chronological order. An IP must be rate-limited if, for some 10-minute window, it sent more than limit requests inside that window. Return all such IPs, sorted in ascending (lexicographic) order.
A 10-minute window is any interval [t, t + 600) seconds.
Example
timestamps = [0, 120, 300, 590, 610, 650, 900]
ips = ["10.0.0.1","10.0.0.2","10.0.0.1","10.0.0.2","10.0.0.1","10.0.0.1","10.0.0.2"]
limit = 2 -> ["10.0.0.1"] (300, 610, 650 fall within [300, 900))
timestamps = [0, 600, 1200], ips = ["1.1.1.1","1.1.1.1","1.1.1.1"], limit = 1 -> []
(requests exactly 600 s apart are never in the same window)
Constraints: 1 ≤ timestamps.length ≤ 10^5; 0 ≤ timestamps[i] ≤ 10^9, non-decreasing; IPs are non-empty strings of digits and dots; 1 ≤ limit ≤ 10^5.
Follow-ups
- The log file is several GB and does not fit in memory.
Code runner format: one JSON value per line: timestamps, ips, limit. Implement flaggedIps(timestamps, ips, limit); the harness prints the sorted list.