Implement piecewise linear interpolation for time-to-empty
Company: Google
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
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.
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
- Skip charging increases and collapse flat SOC segments.
- Compute the time at current SOC and at zero SOC, then subtract.