PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Headway

Implement Journey Counter and Speeder Detector

Last updated: Apr 22, 2026

Quick Overview

This question evaluates parsing, time-series processing, and algorithmic reasoning for detecting complete journeys and speed violations from structured toll log entries, covering numeric timestamp conversion, location and direction extraction, stateful journey grouping, and segment-based speed calculations.

  • hard
  • Headway
  • Coding & Algorithms
  • Software Engineer

Implement Journey Counter and Speeder Detector

Company: Headway

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a highway toll log parser with two classes: `LogEntry` and `LogFile`. Each log line has the format: `timestamp license_plate location booth_type` Example: `44776.619 KTB918 310E MAINROAD` Where: - `timestamp` is a floating-point number in seconds - `license_plate` is a string such as `KTB918` - `location` is an integer followed by a direction letter, such as `310E` or `400W` - `booth_type` is one of `ENTRY`, `MAINROAD`, or `EXIT` A journey is defined as: - one `ENTRY` - followed by zero or more `MAINROAD` records - followed by one `EXIT` Assume the log contains only complete journeys and no missing records. Implement or fix the following: 1. **Parse log entries correctly** - In `LogEntry.__init__(log_line)`, parse the timestamp as a numeric value, not a string. - Parse the location into: - `location`: integer part - `direction`: `EAST` if the suffix is `E`, `WEST` if the suffix is `W` 2. **Implement `count_journeys()`** - Return the total number of complete journeys in the log. 3. **Implement `catch_speeders()`** - Return a collection of license plates for journeys that violate the speed rules. - Each pair of consecutive checkpoints within the same journey represents a `10 km` segment. - Segment speed is: `speed_kmh = (10 * 3600) / time_diff_seconds` A journey is considered speeding if either of the following is true: - any single `10 km` segment has speed at least `130 km/h`, or - at least two `10 km` segments in the same journey have speed at least `120 km/h` Additional rules: - A plate may appear multiple times in the result if it has multiple speeding journeys. - Count each speeding journey only once, even if it contains more than two speeding segments. - Do not compute speeds across different journeys for the same car; in particular, do not connect an `EXIT` from one journey to a later `ENTRY`. You may assume the input order is the log order.

Quick Answer: This question evaluates parsing, time-series processing, and algorithmic reasoning for detecting complete journeys and speed violations from structured toll log entries, covering numeric timestamp conversion, location and direction extraction, stateful journey grouping, and segment-based speed calculations.

Related Interview Questions

  • Debug and extend obstacle-run statistics classes - Headway (medium)
Headway logo
Headway
Feb 20, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

You are given a highway toll log parser with two classes: LogEntry and LogFile.

Each log line has the format:

timestamp license_plate location booth_type

Example:

44776.619 KTB918 310E MAINROAD

Where:

  • timestamp is a floating-point number in seconds
  • license_plate is a string such as KTB918
  • location is an integer followed by a direction letter, such as 310E or 400W
  • booth_type is one of ENTRY , MAINROAD , or EXIT

A journey is defined as:

  • one ENTRY
  • followed by zero or more MAINROAD records
  • followed by one EXIT

Assume the log contains only complete journeys and no missing records.

Implement or fix the following:

  1. Parse log entries correctly
    • In LogEntry.__init__(log_line) , parse the timestamp as a numeric value, not a string.
    • Parse the location into:
      • location : integer part
      • direction : EAST if the suffix is E , WEST if the suffix is W
  2. Implement count_journeys()
    • Return the total number of complete journeys in the log.
  3. Implement catch_speeders()
    • Return a collection of license plates for journeys that violate the speed rules.
    • Each pair of consecutive checkpoints within the same journey represents a 10 km segment.
    • Segment speed is: speed_kmh = (10 * 3600) / time_diff_seconds
    A journey is considered speeding if either of the following is true:
    • any single 10 km segment has speed at least 130 km/h , or
    • at least two 10 km segments in the same journey have speed at least 120 km/h

Additional rules:

  • A plate may appear multiple times in the result if it has multiple speeding journeys.
  • Count each speeding journey only once, even if it contains more than two speeding segments.
  • Do not compute speeds across different journeys for the same car; in particular, do not connect an EXIT from one journey to a later ENTRY .

You may assume the input order is the log order.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Headway•More Software Engineer•Headway Software Engineer•Headway Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.