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