Introduction

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?

Task Statement

Gloria's quest unfolds with two arrays, both brimming with non-negative integers. Starting at the first element of arrayA, she leaps to arrayB based on the index she discovers in arrayA. She then bounces back to arrayA according to the index she stumbles upon in arrayB. Gloria repeats these hops until she returns to where she started in arrayA. What an adventure!

Your challenge is to craft a C++ function that aids Gloria on her trip. The function will take two arrays of integers as inputs, representing arrayA and arrayB. The objective is to find the highest value from arrayB that Gloria jumps to during her voyage.

It is guaranteed that at some point Gloria returns to the starting position.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal