PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

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.

Estimate minutes until SOC reaches zero using a cleaned monotone discharge curve and piecewise-linear interpolation/extrapolation.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([(0,100),(60,50),(120,0)], 25)

Expected Output: 30.0

Explanation: Current 25 percent occurs at minute 90, so 30 minutes remain.

Input: ([(0,100),(10,100),(70,40)], 70)

Expected Output: 70.0

Explanation: Flat duplicate SOC is collapsed to the later time.

Input: ([(0,100),(30,80),(60,90),(90,30)], 15)

Expected Output: 18.0

Explanation: Charging segments are skipped and the final decreasing segment extrapolates to zero.

Hints

  1. Skip charging increases and collapse flat SOC segments.
  2. Compute the time at current SOC and at zero SOC, then subtract.
Last updated: Jun 27, 2026

Loading coding console...

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.

Related Coding Questions

  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
  • Boolean Expression Tree with Leaf Flips - Google (medium)
  • Streaming Points: Remove Any Pair Within a Distance - Google (medium)
  • Most Active Users in a Live Communication Stream - Google (medium)
  • Solve Rooms and Top-K Streams - Google (medium)