Count The Paths

Company: unify

Difficulty: medium

Problem Statement

Count The Paths Problem Description A kingdom has n magical locations, numbered 0 to n - 1 . Location i carries an energy value locations[i] , a positive integer, and no two locations share the same value. You must carry an artifact from location start to location finish . You begin at start holding power units of magical power. In one move you travel from your current location i to any other location j , and the move drains |locations[i] - locations[j]| units of power. Your power must never drop to zero or below : after every move you must still hold at least 1 unit. A move that would leave you with 0 or less cannot be made. A journey is a sequence of locations that begins at start , ends at finish , and in which every step is a valid move. Locations may be visited any number of times, including start and finish themselves, so a journey may pass through finish and come back to it later. Two journeys are different when their sequences of locations are different. Count the number of dif