Maximize Home Battery Arbitrage Across Half-Hourly Prices

Last updated: November 29, 2026

Quick Overview

A home battery holds up to K units and can charge or discharge one unit per half-hour slot. Given the day's half-hourly prices and a round-trip efficiency, compute the maximum profit from charging when cheap and discharging when expensive, starting empty.

Fuse Energy
Coding & Algorithms
Software Engineer
Fuse Energy
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A home battery holds up to K units and can charge or discharge one unit per half-hour slot. Given the day's half-hourly prices and a round-trip efficiency, compute the maximum profit from charging when cheap and discharging when expensive, starting empty.

Fuse installs batteries in homes and trades power in real time, so deciding when a battery should charge or discharge against volatile prices is a core optimisation. The onsite coding round looks for recognising that greedy pairing fails under a capacity limit and that a small DP over state of charge solves it exactly.

What the Interviewer Expects
  • Explain why a simple 'buy low, sell high' greedy can be wrong with a capacity cap
  • Define DP state as state of charge after each slot
  • Include idle, charge and discharge transitions
  • Model efficiency loss on discharge
  • Give O(n * K) time and O(K) space
Key Topics to Cover
Dynamic programming
State of charge
Energy arbitrage
Efficiency losses
Capacity constraints
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add a cycling degradation cost per unit discharged?
  • What if charge and discharge rates differ, or can be fractional?
  • The battery must end the day at least half full. How does the DP change?
  • How would you handle price uncertainty when tomorrow's prices are forecasts?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: prices (pence per unit for each slot), integer capacity, efficiency eta applied to discharge revenue. Each slot the battery charges 1, discharges 1 or idles. It starts empty; ending charg...

High-Level Design

The decision in each slot only depends on how much is stored, so let dp[s] be the best profit after processing the slots so far while holding s units. Transition each slot: idle keeps dp[s]; cha...


Submit Your Answer
Markdown supported

Related Questions