Welcome to a delightful lesson on array traversal! Today, we invite you to join an endearing bunny named Gloria on an intricate quest. Gloria has a soft spot for number games, especially when they involve hopping between arrays.
Our goal on this exciting journey is to assist Gloria through her escapade and identify the maximum value she encounters along the way. Are you ready to embark on this adventure?
Gloria’s journey involves two arrays, arrayA
and arrayB
, filled with non-negative integers. She starts at the first element of arrayA
and uses its value as an index to hop to arrayB
. From there, the value in arrayB
determines her next hop back to arrayA
. Gloria continues hopping until she finds herself back at the starting position in arrayA
.
Your task is to implement a Ruby method, max_value_from_hops(arrayA, arrayB)
, that calculates and returns the highest value Gloria encounters in arrayB
during her journey.
For example, consider:
The method should return . Gloria’s journey would proceed as follows:
