BetaJobprepping.com is in beta and still under construction. New sign-ups are closed.
Start practising
Detection Engineer

Detection Engineer Coding Interview in Python, Explained

What the detection engineer coding interview asks, how messy the log data is, what hidden tests probe, plus a worked Python example and common mistakes.

Updated

The detection engineer coding interview is usually a practical Python task over security logs: parse events, group them by user, host or source, apply a time window, and flag the sequence that looks like an attack. It tests whether your code is correct on messy data and whether you can explain the threat logic behind every condition you write.

This post covers the format, what the hidden tests tend to probe, a worked example on a problem we invented, and the mistakes that cost candidates most. For the whole loop, start with the Detection Engineer interview guide.

What the round looks like in a real loop#

Formats vary by company. Many teams run a live session of 45 to 60 minutes where you write Python, or occasionally a SIEM query language, against a sample of log lines. Some prefer a take-home: write a few rules and a small test harness, then discuss it. A few skip coding and ask for pseudo-logic on a whiteboard, but most detection teams now expect detections to be treated as code, so scripting comes up somewhere.

The problems are rarely algorithm puzzles. Expect dictionaries, sorting, collections.defaultdict and deque, datetime parsing and careful loops. The difficulty is in the data and the edge cases, not the data structures.

In our practice interviews at Kestrel Shield, a fictional managed detection and response provider, live coding takes 13, 18 or 20 minutes depending on the paper length. The exercise is in Python: detecting an authentication attack pattern in logs. You code in the browser, and hidden tests run when you submit.

How messy the data is#

Interview logs are deliberately imperfect, because real telemetry is. Expect some of these:

  • Events not in time order, because they came from several collectors.
  • Timestamps in mixed formats or time zones, or as epoch seconds.
  • Usernames that differ only in case or carry a domain prefix.
  • Lines with missing fields, or a field that is empty rather than absent.
  • Duplicate events from a source that retried.
  • Benign activity that looks almost like the attack, such as a user mistyping a password three times.

Ask about these early. "Can events arrive out of order?" and "Should I treat ANA and ana as the same account?" are questions interviewers want to hear, and the answers save you from failing hidden tests later.

What hidden tests tend to probe#

The visible example usually passes with a naive solution. Hidden tests are where the scoring happens, and they tend to check:

  • Window boundaries: an event exactly at the edge of the window. Decide inclusive or exclusive and say which.
  • Ordering: the same events shuffled. Sort before any sliding-window logic.
  • Thresholds: one below and exactly at the threshold.
  • Per-entity separation: two users interleaved, so state for one must not leak into the other.
  • Reset conditions: whether a success or a quiet period clears the count.
  • Bad input: malformed lines that should be skipped without crashing.
  • Scale: a larger input where re-scanning the whole list for every event becomes too slow.

Talking while coding#

Detection interviews reward narration more than most coding rounds, because the interviewer is scoring detection logic and threat knowledge as well as code. A useful rhythm:

  1. State the attack in one sentence and the fields that prove it.
  2. State your assumptions about ordering, case and malformed data.
  3. Write the simplest correct version, then test it on a tiny input you build by hand.
  4. Name the complexity, usually O(n log n) for the sort and O(n) after.
  5. Say what an attacker would do to evade your rule, and what would cause false positives in production.

A worked example#

Here is a problem we invented in the same genre. Given authentication push events with a user, a timestamp in seconds and a result, flag an MFA fatigue attack: an approved push that follows at least five denied or timed-out pushes for the same user within ten minutes.

The attack logic is that someone with a stolen password keeps triggering push prompts until the tired user approves one. The fields that prove it are user, time and result.

from collections import defaultdict, deque

def mfa_fatigue(events, min_denials=5, window=600):
    """Return (user, approve_ts) where an approval follows
    min_denials or more denied pushes within window seconds."""
    pushes = defaultdict(deque)
    hits = []
    for e in sorted(events, key=lambda e: e["ts"]):
        user, ts, result = e["user"].lower(), e["ts"], e["result"]
        q = pushes[user]
        while q and ts - q[0] > window:
            q.popleft()
        if result in ("denied", "timeout"):
            q.append(ts)
        elif result == "approved":
            if len(q) >= min_denials:
                hits.append((user, ts))
            q.clear()
    return hits

The window is inclusive: a denial exactly 600 seconds before the approval still counts. An approval clears the queue, because a user who approves on the first attempt after a burst has ended the episode. Each event is pushed and popped at most once, so after sorting the loop is linear.

Then test as you go, on cases you choose deliberately:

base = [{"user": "ana", "ts": t, "result": "denied"} for t in range(0, 500, 100)]
ok = {"user": "ana", "ts": 550, "result": "approved"}
assert mfa_fatigue(base + [ok]) == [("ana", 550)]
assert mfa_fatigue(base[:4] + [ok]) == []  # four denials is ordinary friction
assert mfa_fatigue(base + [dict(ok, ts=1200)]) == []  # denials aged out
upper = [dict(e, user="ANA") for e in base]
assert mfa_fatigue(upper + [ok]) == [("ana", 550)]  # case folds to one user
assert mfa_fatigue([ok] + base[::-1]) == [("ana", 550)]  # shuffled input

Out loud, finish with the limits: an attacker who spaces prompts eleven minutes apart slips through, so you might add a longer secondary window; a user whose phone keeps timing out on a train will trigger it, so you would check the source IP of the approved session before escalating.

Common mistakes#

  • Not sorting: sliding windows on unsorted data pass the example and fail hidden tests.
  • Global state: one counter shared across users.
  • Off-by-one boundaries: never stating whether the window edge is in or out.
  • Crashing on a bad line: one malformed event should not stop the detection.
  • Silent coding: long stretches with no explanation leave the interviewer unable to credit your reasoning.
  • No threat framing: correct code with no word on evasion or false positives scores lower on the must-have skills.
  • Testing only the happy path: build the threshold, boundary and shuffle cases yourself before you submit.

For the questions that surround this round, see the detection engineer interview questions, and for how the code is weighed against the rest, see how detection engineer interviews are scored.

When you are ready to try it under time pressure, practise the Detection Engineer interview and get your code checked by hidden tests.

Frequently asked questions#

What language is used in a detection engineer coding interview?#

Python is the most common, because it is what most teams use for enrichment, testing and tooling. Some companies ask for a query in their SIEM language instead, or alongside. Our practice interviews use Python in the browser, and standard library tools such as collections and datetime are enough.

Is the coding round like LeetCode?#

Not usually. The problems lean on parsing, grouping, sorting and time windows rather than clever algorithms. The difficulty comes from messy data and edge cases, and from explaining why each condition maps to attacker behaviour. Practising log parsing is a better use of time than graph puzzles.

How should I handle time windows?#

Sort events by timestamp first, keep per-entity state such as a deque of recent events, evict entries older than the window, and state clearly whether the boundary is inclusive. Then test an event exactly on the boundary, one just outside it, and the same input shuffled.

What do hidden tests check?#

They typically check window boundaries, thresholds, ordering, separation between users or hosts, reset conditions, malformed input and larger inputs for performance. Writing your own small tests for each before submitting is the most reliable way to pass them.

How long is the coding section in the practice interviews?#

Live coding takes 13 minutes in the 30-minute paper, 18 in the 45-minute paper and 20 in the 60-minute paper. You can start a Detection Engineer practice interview at any length; your code runs against hidden tests when you submit.

Read next

GuideDetection Engineer

Detection Engineer Interview Guide with Questions and Prep

How the detection engineer interview works, the detection and threat skills it scores, 8 practice questions, a Python log-analysis round and a 7-day plan.

QuestionsDetection Engineer

Detection Engineer Interview Questions with Strong Answers

28 detection engineer interview questions we wrote, grouped by type, each with why it is asked, what a strong answer does and the follow-up to expect.

ComparisonDetection Engineer

Detection Engineer vs Support Engineer Jobs and Interviews

Detection engineer vs support engineer compared - daily work, skills, how the interviews and coding rounds differ, who each role suits and how to move between.

Practice

Say it out loud.

Reading about an interview isn't the same as doing one. Take a 30, 45 or 60-minute Detection Engineer interview with an AI interviewer and get scored against a real rubric.

Choose an interview