Question: write a c program where You live on a street with N houses. The houses are labelled as 1 2 . . . N, from

write a c program where You live on a street with N houses. The houses are labelled as 1 2 . . . N, from left to right. You live in the house labelled 1, i.e the left-most house. and you wish to reach the house labelled N i.e. the right-most house.

There is a tunnel present in each house. The tunnel present in the house labelled ii can be used to reach any house labelled j, such that jiAi

Determine the minimum number of houses you can visit in order to reach the right-most house. Input Format

First line will contain T, number of testcases. Then the testcases follow. The first line of each testcase contains a single integer N. The second line of each testcase contains N integers : A1,A2...AN.

It is guaranteed that the sum of the values of N over all the test cases doesn't exceed 310^6. Output Format

For each testcase, output in a single integer equal to the minimum number of houses you can visit in order to reach the right-most house. Constraints

1T50 1N10^5 1Ai10^5

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!