Question: BNY Mellon, Online Assessments (OA) 15 Mar, 2026 | The Puzzle of Harmony | Hiking Cost | Complete Solutions & Tips | GCD Optimization & Array Pathing | Mar 15th Campus Assessment
0
Entering edit mode

Question 1: The Puzzle of Harmony

Problem Statement: In a mystical world of balance and order, you are faced with an intricate challenge involving N magical creatures. Each creature carries a specific energy level, represented in the array E. To restore harmony to the realm, you must pair them wisely according to their energy compatibility.

The energy cost of creating harmony between two creatures is determined by the greatest common divisor (GCD) of their energy levels. But there's a twist; you can only choose creatures from the beginning, middle or end of the array to form pairs. Your task is to find and return an integer value denoting the minimum total energy required to harmonize the realm.

Note: The length of N is always even, so always take the second middle magical creature.

Input Specification:

  • input1: An integer value N, denoting the number of magical creatures
  • input2: An integer array E, denoting the energy level of each creature respectively

 


Question 2: Hiking Cost

Problem Statement: 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.

 

Login before adding your answer.

Similar Posts
Loading Similar Posts