Problem 175869 · easy · Phase 01 Prerequisites & Setup

Highest Floor the Elevator Reaches

loops · lists · running maximum · simulation

An elevator starts at floor 0. The list moves holds how many floors it goes up (positive) or down (negative) on each trip. Write highest_floor(moves) that returns the highest floor the elevator ever reaches, including the starting floor 0.

Examples

Input:  moves = [3, -2, 4, -10]
Output: 5
Explanation: floors visited: 3, 1, 5, -5. The highest is 5.

Input:  moves = [-1, -2]
Output: 0
Explanation: it only goes down, so the highest floor is the start, 0.

Constraints

  • 0 <= len(moves) <= 10**5
  • -100 <= moves[i] <= 100

Goals

  • Simulate a position that changes step by step
  • Remember the maximum value reached along the way
Starting Python…