You are given an integer
ndenoting the number of floors in a building, where the floors are numbered from 0 ton - 1.You are also given an integer array
requests, whererequestsrepresents the sequence of floor requests.An elevator starts at floor 0 and follows these rules:
- The elevator moves one floor per second.
- The elevator serves requests in the given order.
- If the elevator is already on the requested floor, no movement is needed.
- After serving a request, the elevator immediately starts moving toward the next request.
Return the total time in seconds required to serve all requests.
1 | class Solution { |