FastPrepDeduplicated Query Registration
Problems/Deduplicated Query Registration

Deduplicated Query Registration

Datadog logoDatadog● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reports describe reusing IDs for equivalent unordered queries, in set and frequency-aware versions. This exercise uses an explicit mode flag and normalized Registered qN/Log output. Case folding, valid grammar, state boundaries and bounds are specified for practice; at-least counts follow author clarification and reported code. The core task matches the reports at about 85%.

Process query and log operations from left to right, starting with an empty registry. Split each body into words and lowercase ASCII letters. Word order does not matter.

  • Q: body registers a query. An equivalent query reuses its existing ID; otherwise assign the next ID starting from one. Return Registered qN for this operation.
  • L: body matches only queries registered so far. Return Log q1, q2 with every matching ID in increasing numeric order, using the same comma-space separator. Return exactly Log when none match.

The countWords flag selects the version:

  • If false, a query is its set of distinct words. Two queries are equivalent when their word sets agree. A log matches when it contains every query word.
  • If true, a query is its word-frequency map. Two queries are equivalent only when every word count agrees. A log matches when each required word appears at least as many times as the query requires. Extra words and extra repetitions are allowed.

Return exactly one output string per operation. Re-registering an equivalent query adds no duplicate match and consumes no new ID. Logs are not retained or replayed when a later query arrives. Each function call starts fresh; the mode stays fixed within that call.

Function

processDeduplicatedQueries(operations: String[], countWords: boolean) → String[]

Examples

Example 1

operations = ["Q: hello world","Q: data failure","Q: world hello","L: hello world we have a data failure","L: oh no system error","Q: system error","L: oh no system error again"]countWords = truereturn = ["Registered q1","Registered q2","Registered q1","Log q1, q2","Log","Registered q3","Log q3"]

The third operation reorders the first query and reuses q1. The first log contains both hello world and data failure, so it matches q1,q2. The next log matches neither. Query system error is then registered as q3, and only the final log can match it.

Example 2

operations = ["Q: a a","Q: a","Q: a a","L: a","L: a a","L: a a a"]countWords = falsereturn = ["Registered q1","Registered q1","Registered q1","Log q1","Log q1","Log q1"]

Set mode reduces both queries to the set containing a. All three registrations reuse q1, and each log contains its required word at least once.

Example 3

operations = ["Q: a a","Q: a","Q: a a","L: a","L: a a","L: a a a"]countWords = truereturn = ["Registered q1","Registered q2","Registered q1","Log q2","Log q1, q2","Log q1, q2"]

Frequency mode distinguishes two required copies of a from one, producing q1 and q2. The one-copy log matches only q2. Both longer logs satisfy both minimum counts, including the three-copy log.

Constraints

  • 0 <= operations.length <= 100
  • Every operation has between 4 and 500 characters.
  • Every operation begins with Q: or L:, followed by at least one ASCII space and a nonempty body. The body contains 1 through 20 alphanumeric ASCII words of length 1 through 20, separated by one or more ASCII spaces; leading and trailing body spaces are allowed.
  • countWords is a boolean.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public String[] processDeduplicatedQueries(String[] operations, boolean countWords) {
    // Write your code here.
}
Checking account…