Box Fro~yo

The Box office is thinking about investing in a rotating frozen yogurt (froyo) machine. The froyo machine has a menu with frozen yogurt flavors that may be included. The machine must move through the flavors one at a time, either moving left or right. The machine is circular, so when the last flavor in the flavors array is reached in either direction, the next flavor is at the other end of the array.

Given the name of the next flavor needed, determine the minimum number of left or right moves to reach it.

Function Description Complete the function flavorchanger in the editor below.

flavorchanger has the following parameter(s):

  • String[] flavors[n]: array of flavor names arranged in the order they appear in the frozen yogurt machine
  • int startIndex: index of the flavor currently dispensing
  • String target: name of the flavor needed

Returns
int: minimum number of moves required to reach the desired flavor

Constraints

  • 1 ≤ n ≤ 100
  • 0 ≤ startIndex ≤ n-1
  • 1 ≤ length of flavors[i] and target ≤ 100
  • target is in flavors

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: