Question: 5 1 0 4 2 3 0 1 2 3 4 5 a 1 . a is a list of 'int' 2 . Length of

510423
012345
a
1. a is a list of 'int'
2. Length of list a is NOT known. YOU CANNOT CALL len(a)
3. If the length of the list is 6(as shown above)
the content of the array is guaranteed to be between 0 to 5.
THERE IS NO REPETATION of numbers
a =[5,1,0,4,2,3];
int h = hop(a,3);
Your task is to find the number of hops to get 3, which is defined as follows:
The top level call is as follows:
a[3]=4
a[4]=2
a[2]=0
a[0]=5
a[5]=3
h = Number of hop is =4
You start from a[x], in this case x =3, a[3]=4, and keep looping
until you get x, which is 3. The number of times you hoped, in this example, is h =4.
One way, to write, using while loop is:
Now write "hop" subroutine as follows:
1. You cannot change interface of hop function
2. You cannot use global/static variables
3. You cannot use any loop statements
like while, do, for and goto
4. You cannot call any function except _hop
5. Your code should not be more than 10 lines
 510423 012345 a 1. a is a list of 'int' 2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!