Tap here to switch tabs
Problem
Submissions

Problem: Elevator Requests II

Try to solve the Elevator Requests II problem.

Statement

An elevator is currently at floor start in a building with n floors, numbered from 00 to n −1- 1.

You are given an integer n, an integer start, and an integer array requests containing distinct floor numbers that must be visited.

The elevator starts at time 00 at floor start and requires ∣a−b∣|a - b| seconds to move between floor aa and floor bb. The penalty for fulfilling a request is defined as the total time elapsed from time 00 until the elevator first arrives at that requested floor. If start is present in requests, its penalty is 00.

Return the minimum total penalty required to fulfill all requests in requests.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

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

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

  • All values in requests are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Elevator Requests II

Try to solve the Elevator Requests II problem.

Statement

An elevator is currently at floor start in a building with n floors, numbered from 00 to n −1- 1.

You are given an integer n, an integer start, and an integer array requests containing distinct floor numbers that must be visited.

The elevator starts at time 00 at floor start and requires ∣a−b∣|a - b| seconds to move between floor aa and floor bb. The penalty for fulfilling a request is defined as the total time elapsed from time 00 until the elevator first arrives at that requested floor. If start is present in requests, its penalty is 00.

Return the minimum total penalty required to fulfill all requests in requests.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

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

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

  • All values in requests are distinct.