Katkat

Filter Logs by an Ordered Severity Threshold

OtherSoftware Engineer · Onsite

Last updated

Filter structured logs by an ordered minimum severity, preserving threshold-and-higher records while handling empty and unknown levels under an explicit contract.

Implement filter_logs(levels: string[], minimum: string, logs: string[][]) -> string[][].

Constraints & Assumptions

  • Levels lists unique nonempty severity names from lowest to highest. There are at most 100 levels; minimum is one of them.
  • Each log is either an empty array (an empty record) or [level,message]. A missing level is represented by the empty string. Unknown or missing levels and empty records are dropped; this handling is an explicit practice policy where the source asks for tests but does not state the outcome.
  • A known qualifying level with an empty message is retained. Message contents never change the record's severity.
  • Preserve record order and duplicate occurrences. Return each retained two-string record unchanged.
  • At most 200000 logs and 2000000 total string characters.

Example

levels = ["DEBUG","INFO","WARN","ERROR"]
minimum = "WARN"
logs = [["INFO","contains WARN text"],["WARN","slow"],
 ["ERROR",""],[],["","missing"],["OTHER","unknown"]]
result = [["WARN","slow"],["ERROR",""]]

Explain why checking the string for the word WARN is incorrect and how the ordered-level model represents the intended requirement. Include exact-threshold, higher/lower-level, missing-level, empty-record, and empty-message cases in your test plan.

Hints

Hint 1

Severity belongs to the structured field: Map level names to their position in the supplied ordering. The free-text message is unrelated to that comparison.