Katkat

Compute Roller Coaster Scores

ZooxMachine Learning Engineer · Technical Screen

Last updated

Tests string parsing, floating-point evaluation, conditional logic, and the implementation of an extensible rule-based scoring engine for ride telemetry.

Problem Statement

Zoox engineers frequently evaluate passenger comfort and thrill metrics from trajectory logs. In this problem, you are tasked with building a scoring engine that processes raw telemetry data from a roller coaster track and computes an overall experience score.

Input telemetry is provided as a single string containing multiple semicolon-separated (;) segment logs. Each segment consists of comma-separated (key:value) metrics. Keys may appear in any order, and extra whitespace around keys or values should be ignored. Unrecognized keys should be safely ignored.

Metrics and Defaults

  • height (float, meters): Drop or element height. Default: 0.0
  • speed (float, m/s): Peak speed during the segment. Default: 0.0
  • inversions (int): Number of inversions in the segment. Default: 0
  • g (float): Peak vertical acceleration in Gs. Default: 1.0
  • jerk (float, m/s^3): Rate of change of acceleration. Default: 0.0

Scoring Rules per Segment

  1. Base Score: (height * 0.5) + (speed * 0.4) + (inversions * 15.0)
  2. G-Force Adjustment:
    • If g > 4.0: add (g - 4.0) * 10.0 (high-G thrill bonus).
    • If 0.0 2.5: subtract (jerk - 2.5) * 8.0 from the segment score.
  3. Floor: A segment's net score before sequential multipliers cannot fall below 0.0.
  4. Intensity Combo Multiplier: If a segment has g >= 3.5 and the immediately preceding segment also had g >= 3.5, multiply the current segment's net score by 1.15.

The final ride score is the sum of all segment scores, rounded to 2 decimal places. If the input log is empty or contains no valid segments, return 0.0.

Function Signature

def compute_coaster_score(telemetry_log: str) -> float:
    pass

Examples

Example 1

telemetry = "height:40.0, speed:25.0, g:4.5, jerk:1.0; height:10.0, speed:15.0, inversions:2, g:1.0, jerk:3.0"
output = compute_coaster_score(telemetry)
# Output: 72.0

Explanation:

  • Segment 1: Base = (40.0 * 0.5) + (25.0 * 0.4) = 30.0. G-bonus = (4.5 - 4.0) * 10.0 = 5.0. Jerk penalty = 0.0. Net = 35.0.
  • Segment 2: Base = (10.0 * 0.5) + (15.0 * 0.4) + (2 * 15.0) = 41.0. G-bonus = 0.0. Jerk penalty = (3.0 - 2.5) * 8.0 = 4.0. Net = 37.0. (Preceding segment had g = 4.5 >= 3.5, but current segment has g = 1.0 < 3.5, so no combo multiplier).
  • Total: 35.0 + 37.0 = 72.0.

Example 2

telemetry = "speed:30.0, g:3.8; speed:20.0, g:4.0"
output = compute_coaster_score(telemetry)
# Output: 23.5

Explanation:

  • Segment 1: Base = 30.0 * 0.4 = 12.0. Net = 12.0. (g = 3.8 >= 3.5).
  • Segment 2: Base = 20.0 * 0.4 = 8.0. G-bonus = 0.0. Net before combo = 8.0. Both current and preceding segment had g >= 3.5, so net = 8.0 * 1.15 = 9.2. Wait, G-bonus for g=4.0 is 0.0. Base is 8.0. Net before combo = 8.0. With combo: 8.0 * 1.15 = 9.2. Total = 12.0 + 9.2 = 21.2.

Constraints

  • 0 <= len(telemetry_log) <= 100_000
  • Number of segments <= 5,000
  • All numeric values are non-negative floats/ints
  • Floating-point calculations should maintain standard double-precision before the final rounding

Hints

Hint 1

Split the input first by semicolon to isolate segments, then by commas and colons to extract key-value mappings for each segment.

Hint 2

Define a helper function or dataclass to hold parsed attributes with their default values so that missing attributes are handled consistently.

Hint 3

Keep track of a boolean flag indicating whether the previous segment satisfied the high-G condition (`g >= 3.5`) to apply the 1.15x combo multiplier correctly.

Follow-up questions

  • How would you refactor this scoring logic so new ride dynamics (e.g., lateral sway, tunnel lighting bonuses) can be added via a plugin or rule-engine architecture without modifying core code?
  • If telemetry is streamed in real time over a network socket with occasional packet drops or malformed segments, how would you make the parser resilient and fault-tolerant?
  • How would you adapt the scoring engine to evaluate passenger comfort vs. thrill dynamically depending on passenger profile (e.g., child vs. thrill-seeker)?