PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to model and optimize a discrete decision under resource constraints, testing algorithmic optimization, numerical reasoning, handling of edge cases, and attention to integer/64-bit arithmetic.

  • hard
  • Uber
  • Coding & Algorithms
  • Software Engineer

Minimize time using elevator then climb stairs

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

## Problem You need to go up **n floors** (from floor 0 to floor n). You may: 1. **Take the elevator first (at most once, only at the start)** for `k` floors, where `0 ≤ k ≤ n`. - For each elevator floor traveled: - You **gain** `e1` energy. - You spend `t1` time. - After riding `k` floors, your energy is `E = k * e1`. 2. **Then climb the remaining `n - k` floors by stairs**. - For each stair floor climbed: - If your current energy before climbing that floor is `E`, the time spent on that floor is: \[ \lceil c / E \rceil \] - After climbing that floor, your energy decreases by `e2`: `E := E - e2` - **Energy must never become negative**, meaning before every stair step you must have `E ≥ e2` (so that after subtracting `e2` you still have `E ≥ 0`). Your task is to choose `k` to **minimize the total travel time**. ## Input Five integers: - `n`: number of floors to go up - `e1`: energy gained per elevator floor - `t1`: time per elevator floor - `e2`: energy spent per stair floor - `c`: constant used in stair time formula ## Output Return the **minimum possible total time** to reach floor `n`. - If it is **impossible** to reach floor `n` for any `k` (i.e., you can’t complete the stair portion without energy going negative), return `-1`. ## Notes / Clarifications - The elevator can be taken **only once and only before any stair climbing**. - Stair time uses the **current energy before** spending `e2` for that floor. - Use 64-bit arithmetic where appropriate.

Quick Answer: This question evaluates a candidate's ability to model and optimize a discrete decision under resource constraints, testing algorithmic optimization, numerical reasoning, handling of edge cases, and attention to integer/64-bit arithmetic.

Choose elevator floors k, then climb remaining floors if energy never becomes negative. Return minimum total time or -1.

Constraints

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

Examples

Input: (5, 3, 2, 1, 10)

Expected Output: 9

Explanation: Try all elevator split points.

Input: (3, 1, 5, 2, 10)

Expected Output: 15

Explanation: Need enough elevator energy.

Input: (0, 1, 1, 1, 10)

Expected Output: 0

Explanation: Already at target.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
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
  • AI Coding 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

  • Thread-Safe Token-Bucket Rate Limiter - Uber
  • Quadtree for 2D Geospatial Points - Uber
  • Group Anagrams - Uber
  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)