Minimum Bus Fare to the Last School
EasyP3Coding
There are N schools in a row, one unit apart, and Neelam wants to travel from school 1 to a point one unit past school N (position N + 1). She can board a bus at any school i, and then pays c[i-1] rupees for each unit of distance travelled on that bus (the array is 0-indexed, so c[i-1] is the rate at school i). She may get off at any school and board another bus there, paying that school's rate for the next stretch.
Return the minimum total fare to get from school 1 to position N + 1.
Example 1
- Input
- c = [4,2,3,1,5]
- Output
- 10
- Why
- Ride the school-1 bus one unit (4), switch to school 2 (2) for two units, then school 4 (1) for two units: 4 + 2 + 2 + 1 + 1.
Example 2
- Input
- c = [5]
- Output
- 5
Constraints
- 1 <= N <= 10^5
- 1 <= c[i] <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.