Question bank › Dynamic Programming
Dsa Dynamic Programming Easy

Elevator Management System

You are tasked with managing an elevator system in a building. The building has `n` floors numbered from `0` to `n-1`. The elevator starts on the ground floor (floor `0`), and it can only visit each floor once. Each time it visits a floor, it collects a number of passengers, given in an array `passengers` where `passengers[i]` represents the number of passengers on floor `i`. The elevator can move up or down by one floor at a time until it reaches the top floor, and then it can return to the ground floor. Your goal is to determine the maximum number of passengers the elevator can collect before returning to the ground floor. Implement a function that reads the number of floors and the list of passengers from standard input and prints the maximum number of passengers that can be collected. Input format: - The first line contains an integer `n` (1 ≤ n ≤ 100). - The second line contains `n` space-separated integers representing the `passengers` array (0 ≤ passengers[i] ≤ 100). Output format: - Print a single integer, the maximum number of passengers that can be collected. Example: Input: 5 1 2 3 4 5 Output: 15 Here, the elevator can visit all floors and collect all passengers before returning.

Key concepts

dynamic_programminggreedyarray

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.