Is This a Full Cycle?

Published by Mubashir Hassan in

Say you want to traverse an array of integers starting at the first item and using each value as a pointer of what item to visit next. For example, you would traverse the array [1, 4, 3, 0, 2] in the following manner:

List

Because you visit every item once and go back to the starting point, the array [1, 4, 3, 0, 2] is a "full cycle".

Create a function that returns true if the input array is a full cycle, or false otherwise.

Examples

full_cycle([1, 4, 3, 0, 2]) ➞ true

full_cycle([1, 4, 0, 3, 2]) ➞ false

full_cycle([5, 3, 4, 2, 0, 1]) ➞ true

Notes

Test arrays won't include any negative integers.

Watch a quick demo on how Edabit works.