PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Implement piecewise linear interpolation for time-to-empty

Last updated: Mar 29, 2026

Quick Overview

This question evaluates numerical interpolation, time-series data cleaning, monotonicity preservation, extrapolation, and numerical stability skills applied to battery discharge curves, and falls under coding and algorithms within a data science domain.

  • medium
  • Google
  • Coding & Algorithms
  • Data Scientist

Implement piecewise linear interpolation for time-to-empty

Company: Google

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a function time_to_empty(checkpoints, current_soc) that returns minutes until SOC reaches 0, using piecewise linear interpolation on a discharge curve. Input: - checkpoints: a sorted list of (t_min, soc_percent) pairs from a single session. - current_soc: the current SOC percentage (0–100). Rules and edge cases: - Assume soc_percent is nonincreasing during discharge; skip any charging segments (soc increase) and handle duplicate SOC levels by collapsing segments. - If there is no exact soc=0 point, linearly extrapolate using the last valid segment; if there are gaps around current_soc, interpolate within the bracketing segment. - Must run in O(n) time and O(1) extra space after sorting. Tests to satisfy: - checkpoints = [(0,100),(60,50),(120,0)], current_soc = 25 → expected 30 minutes. - Explain how your function maintains monotonicity of estimated remaining time with respect to current_soc and why it is numerically stable.

Quick Answer: This question evaluates numerical interpolation, time-series data cleaning, monotonicity preservation, extrapolation, and numerical stability skills applied to battery discharge curves, and falls under coding and algorithms within a data science domain.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Coding & Algorithms
3
0

Time-to-Empty from a Discharge Curve (Piecewise Linear Interpolation)

Implement a function time_to_empty(checkpoints, current_soc) that returns the number of minutes until the battery's state of charge (SOC) reaches 0. Use piecewise linear interpolation on a discharge curve built from time-stamped SOC measurements.

Inputs

  • checkpoints: a list of (t_min, soc_percent) tuples sorted by time (ascending). All points are from a single session.
  • current_soc: the current SOC percentage in [0, 100].

Rules and Edge Cases

  • Discharge-only assumption: SOC is nonincreasing during discharge.
    • Skip any charging segments (i.e., where SOC increases).
    • Handle duplicate SOC levels (flat segments) by collapsing them into a single point.
  • Interpolation and extrapolation:
    • If there is no exact soc = 0 point in the data, linearly extrapolate using the last valid decreasing segment.
    • If current_soc falls between two SOC levels, interpolate within the bracketing segment.
    • If current_soc falls outside the observed SOC range after cleaning (above the max or below the min), extrapolate using the first/last valid decreasing segment, respectively.
  • Performance: O(n) time and O(1) extra space after sorting.

Output

  • Minutes (float) until SOC reaches 0 from current_soc.

Tests to Satisfy

  • checkpoints = [(0, 100), (60, 50), (120, 0)], current_soc = 25 → expected 30 minutes.

Explain

  • Explain how your function maintains monotonicity of the estimated remaining time with respect to current_soc and why it is numerically stable.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Data Scientist•Google Data Scientist•Google Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.