Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A city has N Tram stations numbered from 1 to N that are connected to one another and form a circle. You are given an
A city has N Tram stations numbered from to N that are connected to one another and form a circle. You are given an array ticketcost where ticketcosti is the cost of a ticket between the stops number i and i N The Tram can travel in both directions ie clockwise and anticlockwise.
Return the minimum cost to travel between the given start and finish station.
You are given an integer N where N represents the total number of the tram stations, an integer start which represents the start station, and an integer finish which represents the finish station. You are given an array of positive integers ticketcost where ticketcosti represents the ticket cost between the station number i and i N
Task
Determine the minimum cost to travel between the given start and finish station.
Example
Assumptions
N
start
finish
ticketcost
Approach
path
path
Path will give the minimum cost. Therefore return
Function description
Complete the Solve function provided in the editor below that takes the following arguments and finds the minimum cost to travel between the given start and finish station:
N: Represents the total number of tram stations
start: Represents the start station
finish: Represents the finish station
ticketcost: Represents ticketcosti denoting the ticketcost between the station number i and i N
Input format
The first line contains an integer N denoting the total number of tram stations.
The second line contains an integer start denoting the start station.
The third line contains an integer finish denoting the finish station.
The fourth line contains an N spaceseparated integer array ticketcost ticketcosti represents the ticketcost between the station number i and i N
Output format
Return the minimum cost to travel between the given start and finish station.code in java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started