PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Minimize time using elevator then climb stairs

Last updated: Mar 29, 2026

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.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
Uber logo
Uber
Oct 18, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

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:

⌈c/E⌉\lceil c / E \rceil⌈c/E⌉

 - 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.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.