Company: BNY Codedivas 2026
Difficulty: medium
Hiking Cost John, an avid hiker, wants to go on a hiking trip across a series of trails with varying difficulty levels. The difficulty levels of the trails are given in an array A of size N . John's objective is to start at the first trail, hike through all the trails, and then return to the starting trail. The cost of the trip is calculated as follows: The cost of shifting from one trail to another is determined by the absolute difference in difficulty levels between the current trail and the trail John shifts to. The overall cost of the hiking experience is defined by the maximum cost incurred towards all the shifts John makes during his journey in both directions. Your task is to help John find and return an integer value representing the minimum cost among the highest costs of all the shifts he makes during the hiking trip. Note: John can hike to each trail at most once during his journey in each direction he can skip any trail if he wants to. The difficulty level of the first trai