Parse logs into URL-pattern counts and response-time statistics

Quick Overview

Parse request logs with regular expressions and group response times into six configured URL patterns. Produce call counts, means, and medians while defining malformed-line handling and accounting for memory and regex costs.

Parse logs into URL-pattern counts and response-time statistics

Company: Gusto

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

Process log lines and return one statistics object for each matched URL pattern. Each object must contain the response URL pattern, call count, mean response time, and median response time. The service has exactly six configured URL patterns. Use regular expressions to extract the URL and response time from each line and to match the URL to its pattern. Maintain a map from URL pattern to its response-time list while processing the logs, then compute the requested statistics. The exact log format and six patterns are supplied configuration, not hardcoded assumptions. For a self-contained implementation, accept an extraction regex with named groups `url` and `response_ms`, and six `(pattern_name, regex)` definitions. Decide how invalid lines and ambiguous matches are handled. ```hint Preserve enough information Consider which of the requested statistics can be updated from a running sum and which needs more information about the response-time distribution. ``` ### Constraints and Clarifications Assume response times are nonnegative integer milliseconds for the exercise. Match route regexes against the full extracted URL. Report observed patterns only, and use the arithmetic mean of the two central values for an even-sized median. These choices fill gaps in the reported task. ### Clarifying Questions - Does URL matching include the query string, or should it be normalized first? - Can two configured patterns match one URL, and should that be rejected or resolved by priority? - Should malformed lines be skipped with a diagnostic count or stop the entire run? - Must the median be exact, and will all response times fit in memory? ### What a Strong Answer Covers - Extraction and six-pattern matching with an explicit malformed-input policy - Per-pattern response-time collection and correct mean and median calculations - Output naming, numeric behavior, and a worked example - Time and memory cost, including regex matching and sorting ### Follow-up Questions - How would you compute the same statistics when the input cannot fit in memory? - What would an approximate median change in the output contract? - How would you test overlapping patterns and a line containing an invalid response time?

Overview: Parse request logs with regular expressions and group response times into six configured URL patterns. Produce call counts, means, and medians while defining malformed-line handling and accounting for memory and regex costs.

Read the full Gusto Software Engineer interview experience this question came from

Gusto logo
Gusto
Dec 2, 2026
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
0
0

Process log lines and return one statistics object for each matched URL pattern. Each object must contain the response URL pattern, call count, mean response time, and median response time. The service has exactly six configured URL patterns.

Use regular expressions to extract the URL and response time from each line and to match the URL to its pattern. Maintain a map from URL pattern to its response-time list while processing the logs, then compute the requested statistics.

The exact log format and six patterns are supplied configuration, not hardcoded assumptions. For a self-contained implementation, accept an extraction regex with named groups url and response_ms, and six (pattern_name, regex) definitions. Decide how invalid lines and ambiguous matches are handled.

Constraints and Clarifications

Assume response times are nonnegative integer milliseconds for the exercise. Match route regexes against the full extracted URL. Report observed patterns only, and use the arithmetic mean of the two central values for an even-sized median. These choices fill gaps in the reported task.

Clarifying Questions Guidance

  • Does URL matching include the query string, or should it be normalized first?
  • Can two configured patterns match one URL, and should that be rejected or resolved by priority?
  • Should malformed lines be skipped with a diagnostic count or stop the entire run?
  • Must the median be exact, and will all response times fit in memory?

What a Strong Answer Covers Guidance

  • Extraction and six-pattern matching with an explicit malformed-input policy
  • Per-pattern response-time collection and correct mean and median calculations
  • Output naming, numeric behavior, and a worked example
  • Time and memory cost, including regex matching and sorting

Follow-up Questions Guidance

  • How would you compute the same statistics when the input cannot fit in memory?
  • What would an approximate median change in the output contract?
  • How would you test overlapping patterns and a line containing an invalid response time?