The Circular jump (Lowe)
Practice
4 (13 votes)
Approved
Breadth first search
Easy
Graphs
Problem
20% Success 7869 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are N chairs arranged around a circular table. Each chair has a number \(Num_i\) written on it. Any person sitting on a chair i can jump \(Num_i\) number of indices towards left or right, You are sitting on chair X and you have to reach chair Y. Tell the minimum number of jumps required by you. If its impossible to reach then print 1.

Example :- If your sitting on chair 4 and it has number 2 written on it then you can either jump to chair number 2 or chair number 6.

Constraints
\(1<=T<=100\)
\(1<=N<=10^4\)
\(1<=Num_i<=10^9\)
\(1<=X,Y<=N\)

Format of the input file:
First line : T i.e number of testcases.
For each testcase :
First line : Three space separated integers N , X and Y.
Second line : N space separated integers denoting the chNum.

Format of the output file:
For each testcase print the answer in a separate line.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
444 votes
Tags:
Breadth First SearchDepth First SearchDynamic ProgrammingEasyGraphsMathNumber Theory
Points:30
43 votes
Tags:
AlgorithmsBreadth First SearchEasyGraphs
Points:30
61 votes
Tags:
Ad-HocAlgorithmsBreadth First SearchEasyGraphs