Problem 188974 · easy · Phase 01 Prerequisites & Setup

Elevator Trip Log

loops · conditionals · arithmetic

An elevator starts on floor 1 and serves requests in the order given. Moving from floor a to floor b travels |a - b| floors and counts as one stop. A request for the floor the elevator is already on is ignored (no travel, no stop). Return [floors_travelled, stops].

Examples

Input:  requests = [5, 5, 2, 8]
Output: [13, 3]
Explanation: 1->5 (4), 5 ignored, 5->2 (3), 2->8 (6): 13 floors, 3 stops.

Input:  requests = [1]
Output: [0, 0]

Constraints

  • 0 <= len(requests) <= 1000, 1 <= requests[i] <= 100

Goals

  • Track a current position while processing requests in order
  • Count only the requests that actually cause movement
Starting Python…