Slowest Charger Rate That Tops Up Every EV Before Shift

Last updated: November 29, 2026

Quick Overview

An overnight depot has one charger and a list of energy needs in kWh for each EV. Each hour the charger serves one car at rate r kWh per hour (leftover capacity that hour is wasted). Return the minimum integer r so every car is charged within h hours.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


An overnight depot has one charger and a list of energy needs in kWh for each EV. Each hour the charger serves one car at rate r kWh per hour (leftover capacity that hour is wasted). Return the minimum integer r so every car is charged within h hours.

An Uber online assessment item framed around the EV fleet programs for drivers. It checks whether you recognize a monotone feasibility check and binary search on the answer rather than trying rates one by one.

What the Interviewer Expects
  • Notes that a higher rate never needs more hours, so feasibility is monotone
  • Computes hours for a rate with ceiling division
  • Binary searches r between 1 and max(needs)
  • Avoids floating point for the ceiling
  • States O(n log max) time
Key Topics to Cover
binary search on answer
monotonic predicate
ceiling division
greedy check
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
  • What if the depot has c chargers that can each serve one car per hour?
  • What if cars arrive at different hours?
  • How would you pick the rate when electricity price varies by hour?
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: list of positive kWh needs, hours h >= len(needs).
  • Output: smallest integer rate r that finishes in at most h hours.
  • A car needing x kWh occupies the charger for ceil(x / r) hours....
High-Level Design

For a fixed rate r the total hours is sum(ceil(x / r)), which can only shrink as r grows. So the set of feasible rates is a suffix of the integers, and binary search finds its first element. The low...


Submit Your Answer
Markdown supported