Tap here to switch tabs
Problem
Submissions

Problem: Elevator Requests I

Elevator Requests I starts an elevator at floor zero in a building with a given number of floors and provides an ordered array of requested floors. Return the total time to serve them all.

Statement

You are given an integer n representing the total number of floors in a building, where floors are indexed from 00 to n −1- 1. You are also given an integer array requests.

An elevator begins at floor 00 and processes each request in requests in the given order. Moving between any two floors takes an amount of time equal to the absolute difference between their floor numbers.

Return the total time required to complete all requests.

Constraints:

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq requests.length ≤100\leq 100

  • 0≤0 \leq requests[i] ≤\leq n −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Elevator Requests I

Elevator Requests I starts an elevator at floor zero in a building with a given number of floors and provides an ordered array of requested floors. Return the total time to serve them all.

Statement

You are given an integer n representing the total number of floors in a building, where floors are indexed from 00 to n −1- 1. You are also given an integer array requests.

An elevator begins at floor 00 and processes each request in requests in the given order. Moving between any two floors takes an amount of time equal to the absolute difference between their floor numbers.

Return the total time required to complete all requests.

Constraints:

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq requests.length ≤100\leq 100

  • 0≤0 \leq requests[i] ≤\leq n −1- 1