Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Test-case 1: You use the tunnel present in the house labelled 11 to reach the house labelled 33. Thus, you visited 22 houses in total, the house labelled 11 and the house labelled 33.

Test-case 2: One of the ways to reach the house labelled NN is to

Use the tunnel in house labelled 11 to reach house labelled 22.

Use the tunnel in house labelled 22 to reach house labelled 66.

Use the tunnel in house labelled 66 to reach house labelled 88.

Thus we visit 44 houses in total. There exists no way to reach house labelled NN by visiting less than 44 houses.

INPUT : (JUST A EXAMPLE)

2

3

2 1 1

8

3 4 2 1 1 2 1 8

OUTPUT :

2

4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

=+1 Is the decision fair to employees?

Answered: 1 week ago