We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That's a great way to visualize it! To implement it though, we can create a function that largely just uses the values from the given array c. (Note that I'm using Python logic here, so len(c) is the given length of the array c.)
Set a variable for maximum distance, initialized at c[0] -- in other words, the distance from city 0 to the first station, or the length of the first chain.
If there are multiple stations (len(c) > 1), set a loop from 1 to len(c) to calculate the distances from a city located exactly between them -- half the length of each middle chain. You can use a floor value on the quotient to avoid adding to the length. Compare these values to the initial maximum distance variable.
Compare the final maximum distance value to the distance from the last station (c[len(c)-1]) to the last city (n-1) -- in other words, the length of the last chain. Output the result.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flatland Space Stations
You are viewing a single comment's thread. Return to all comments →
That's a great way to visualize it! To implement it though, we can create a function that largely just uses the values from the given array c. (Note that I'm using Python logic here, so len(c) is the given length of the array c.)