Tap here to switch tabs
Problem
Submissions

Problem: Elevator Requests I

med
30 min
Try to solve the Elevator Requests I problem.

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

med
30 min
Try to solve the Elevator Requests I problem.

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