Datadog software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
No verified questions yet for Datadog.
ERROR: db-42 produces the tokens error, db, and 42.A query matches a log if every distinct token in the query occurs somewhere in the log. Token order and repetition do not matter, and matching uses whole tokens rather than substrings. Thus, database timeout matches TIMEOUT connecting to database, but error does not match errors.Each registration receives a unique, monotonically increasing integer ID, starting at 1. Identical queries registered separately receive different IDs and remain independent. A cancellation deactivates only the specified ID. For each log, return all matching active IDs in ascending order. Logs are not retained or matched against future registrations.The query population is large, while most logs share tokens with only a small fraction of queries. Your implementation must use a searchable index rather than scan every active query for each log. Cancellation must also avoid scanning unrelated queries. Query cancellation is an extension to the reported registration-and-log-matching exercise.Function or class signatureLogQueryMatcher() — construct an empty matcher.register(query: str) -> int — register a query and return its new ID.unregister(query_id: int) -> bool — deactivate an active ID and return true; return false if it is unknown or already inactive.match(log: str) -> list[int] — return matching active IDs in ascending order.[
{"method": "register", "query": "database timeout"},
{"method": "register", "query": "ERROR"},
{"method": "register", "query": "timeout timeout"},
{"method": "match", "log": "ERROR: database connection TIMEOUT"},
{"method": "match", "log": "database errors"}
]Output:[1, 2, 3, [1, 2, 3], []]Explanation: The first log contains every required token of all three queries. Repeated
timeout tokens in query 3 count only once. The second log lacks timeout, and errors is not the token error.Example 2:Input:[
{"method": "register", "query": "api-500"},
{"method": "register", "query": "500 API"},
{"method": "match", "log": "api returned 500; API retry"},
{"method": "unregister", "query_id": 1},
{"method": "unregister", "query_id": 1},
{"method": "match", "log": "API 500"},
{"method": "register", "query": "api"},
{"method": "match", "log": "api500"},
{"method": "match", "log": "api"}
]Output:[1, 2, [1, 2], true, false, [2], 3, [], [3]]Explanation: Queries 1 and 2 have the same token set but independent IDs. Cancelling query 1 leaves query 2 active. IDs are never reused. The token
api500 is neither api nor 500, so it matches no active query.Constraints:error now occurs in nearly every query and log, making its posting list expensive to visit. How would you index each query under one selected anchor token, verify candidates against their complete token sets, and choose or rebalance anchors as token frequencies change? Explain how you preserve correctness and what worst-case work remains unavoidable.id, timestamp_ms, organization, service, message, and bytes. bytes is the supplied ingestion weight, not the length of message.timestamp_ms, breaking ties by their original input position. Return results in processing order.error matches ERROR and allows 100 bytes per service per organization over 1000 ms; timeout matches timeout and allows 60 bytes per service per organization over 1000 ms.W, usage at time t is the sum of bytes from previously accepted records matching that rule and scope with timestamps in (t − W, t]. Previously processed records at timestamp t count; a record exactly at t − W does not.ignored. Otherwise, reject it if current_usage + bytes > limit for any matching rule. Equality is allowed. An accepted record consumes its full byte weight in every matching rule; a rejected or ignored record consumes nothing.accepted, rejected, or ignored.evaluate_logs(logs: list[dict[str, str]]). The return type is up to you; the examples use JSON arrays of result objects.Example 1:{
"logs": [
{"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR database","bytes":"60"},
{"id":"b","timestamp_ms":"100","organization":"acme","service":"api","message":"ERROR timeout","bytes":"50"},
{"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"timeout upstream","bytes":"40"},
{"id":"d","timestamp_ms":"300","organization":"acme","service":"api","message":"INFO healthy","bytes":"20"},
{"id":"e","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"20"}
]
}[
{"id":"a","status":"accepted"},
{"id":"b","status":"rejected"},
{"id":"c","status":"accepted"},
{"id":"d","status":"ignored"},
{"id":"e","status":"accepted"}
]a consumes 60 error bytes. b would bring error usage to 60 + 50 = 110 > 100, so it consumes neither error nor timeout budget. c consumes 40 timeout bytes. d matches neither query. At time 1000, a has expired: e brings error usage to 20 and timeout usage to 40 + 20 = 60, so both limits pass.Part 2 — Organization policies and explainable decisionsevaluate_logs_with_rules(logs: list[dict[str, str]], additional_rules: list[dict[str, str]]). Each additional rule has string fields id, query, scope, limit_bytes, and window_ms. scope is either service or organization; a service scope is keyed by both organization and service, while an organization scope is keyed only by organization.matched_rules and violations lexicographically by rule ID. Each violation contains rule_id, used_bytes before this record, attempted_bytes equal to used_bytes + record.bytes, and limit_bytes. Accepted and ignored records have an empty violations list.{
"additional_rules": [
{"id":"org_errors","query":"ERROR","scope":"organization","limit_bytes":"120","window_ms":"1000"}
],
"logs": [
{"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR","bytes":"70"},
{"id":"b","timestamp_ms":"100","organization":"acme","service":"worker","message":"ERROR","bytes":"40"},
{"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"ERROR","bytes":"20"},
{"id":"d","timestamp_ms":"300","organization":"acme","service":"worker","message":"timeout","bytes":"50"},
{"id":"e","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"30"}
]
}[
{"id":"a","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
{"id":"b","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
{"id":"c","status":"rejected","matched_rules":["error","org_errors"],"violations":[{"rule_id":"org_errors","used_bytes":110,"attempted_bytes":130,"limit_bytes":120}]},
{"id":"d","status":"accepted","matched_rules":["timeout"],"violations":[]},
{"id":"e","status":"accepted","matched_rules":["error","org_errors","timeout"],"violations":[]}
]a and b use different service budgets but together consume 70 + 40 = 110 organization error bytes. For c, the service error total would be 70 + 20 = 90, but the organization total would be 110 + 20 = 130 > 120; it is rejected without changing either budget. d consumes 50 timeout bytes only for worker. At time 1000, a expires: e produces service error usage 30, organization error usage 40 + 30 = 70, and api timeout usage 30.Example 3:{
"additional_rules": [
{"id":"org_errors","query":"ERROR","scope":"organization","limit_bytes":"120","window_ms":"1000"},
{"id":"org_timeouts","query":"timeout","scope":"organization","limit_bytes":"50","window_ms":"1000"}
],
"logs": [
{"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR timeout","bytes":"40"},
{"id":"b","timestamp_ms":"100","organization":"acme","service":"worker","message":"ERROR","bytes":"80"},
{"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"ERROR timeout","bytes":"70"},
{"id":"d","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"20"},
{"id":"e","timestamp_ms":"1100","organization":"acme","service":"api","message":"ERROR timeout","bytes":"40"}
]
}[
{"id":"a","status":"accepted","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[]},
{"id":"b","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
{"id":"c","status":"rejected","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[{"rule_id":"error","used_bytes":40,"attempted_bytes":110,"limit_bytes":100},{"rule_id":"org_errors","used_bytes":120,"attempted_bytes":190,"limit_bytes":120},{"rule_id":"org_timeouts","used_bytes":40,"attempted_bytes":110,"limit_bytes":50},{"rule_id":"timeout","used_bytes":40,"attempted_bytes":110,"limit_bytes":60}]},
{"id":"d","status":"accepted","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[]},
{"id":"e","status":"rejected","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[{"rule_id":"org_timeouts","used_bytes":20,"attempted_bytes":60,"limit_bytes":50}]}
]a consumes 40 bytes in four independent budgets. b brings organization error usage to 40 + 80 = 120. c violates all four matching rules: 40 + 70 = 110 > 100, 120 + 70 = 190 > 120, 40 + 70 = 110 > 50, and 40 + 70 = 110 > 60. At time 1000, a expires, so d produces totals of 20 service-error bytes, 80 + 20 = 100 organization-error bytes, 20 organization-timeout bytes, and 20 service-timeout bytes. At time 1100, b expires; e would produce 60 bytes in each matching budget, exceeding only the organization-timeout cap of 50. Its rejection changes no budget.Notes:error and timeout. Queries are nonempty. Every function call starts with empty usage state.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free