← Uber Interview Insights

Uber·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE online assessment with a single algorithmic problem involving energy and time tradeoffs across elevator and stair segments. The problem looks approachable until you realize the feasibility constraint makes it non-trivial and you can't just brute force it cleanly.

Questions Asked (1)

Q1

Given n total floors, you take an elevator for m floors (gaining e1 energy and spending t1 time per floor) then climb the remaining floors by stairs (each stair floor costs e2 energy and takes ceil(c / current_energy) time). Find the integer split m that minimizes the absolute difference between total elevator time and total stair time, subject to having enough energy to complete the stairs.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The energy feasibility check is what makes this annoying.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and define the objective function: total elevator time = m * t1, total stair time = sum over remaining floors of ceil(c / current_energy), where current_energy decreases by e2 per floor. Then, since the objective is to minimize the absolute difference between these times, we can iterate over possible m from 0 to n, compute both times, check energy feasibility, and track the minimum difference. Optimize by noting monotonicity: elevator time increases linearly with m, while stair time decreases as m increases (fewer stairs), so the difference is unimodal; we can use binary search or two-pointer to find the optimal m efficiently.

Pro tip: Always discuss edge cases and constraints upfront (e.g., if e1 is insufficient to gain energy, or if initial energy is too low to climb any stairs). Also, mention that the stair time formula depends on current energy, which changes per floor, so a naive sum is O(n) per m, leading to O(n^2) overall; propose an O(n) or O(n log n) solution by precomputing prefix sums or using binary search on m.

1. Clarify problem and constraints

Ask clarifying questions: Are e1, e2, t1, c, and initial energy given? Can m be 0 or n? Is energy allowed to go negative? Confirm that stair time per floor is ceil(c / current_energy) and that current_energy updates after each floor.

2. Define objective and feasibility

Express total elevator time as m * t1 and total stair time as the sum of ceil(c / E_i) for i from m+1 to n, where E_i is the energy before climbing floor i. Feasibility requires that energy never drops below 0 during stairs, i.e., initial_energy + m * e1 - (n - m) * e2 >= 0 and also that at each step energy is sufficient to compute ceil(c / E_i) (E_i > 0).

3. Analyze monotonicity and search space

Observe that as m increases, elevator time increases linearly, while stair time decreases (since fewer floors to climb). The absolute difference is unimodal, so we can binary search for the m where elevator time and stair time cross, then check nearby integers. Alternatively, iterate m from 0 to n if n is small.

4. Optimize computation of stair time

For a given m, computing stair time naively takes O(n-m) time. To optimize, precompute prefix sums of stair times for all possible starting energies? But energy depends on m. Instead, note that energy at floor i is initial_energy + m*e1 - (i-m-1)*e2. This is linear in m, so stair time for a fixed floor is a function of m. We can precompute for each floor the energy as a function of m and then compute sum efficiently using binary search or by iterating m and updating incrementally.

5. Implement and test

Write code that iterates m from 0 to n, checks feasibility, computes both times, and tracks the minimum difference. Test with edge cases: m=0 (all stairs), m=n (all elevator), insufficient energy, large n. Discuss time complexity and possible optimizations.

Key Points to Mention

  • Clarify the problem statement and constraints before diving into solution.
  • Define the objective function and feasibility condition clearly.
  • Explain the monotonicity of elevator time vs. stair time to justify binary search.
  • Discuss the energy update per floor and how it affects stair time computation.
  • Propose an efficient algorithm (e.g., O(n) or O(n log n)) and analyze time/space complexity.
  • Handle edge cases: m=0, m=n, insufficient energy, and large inputs.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.