All Problems

Problem title

Difficulty

Avg time to solve

Square Root

Easy

15 mins

Merge Two Sorted Linked Lists

Moderate

15 mins

Longest Consecutive Sequence

Moderate

40 mins

Time To Burn Tree

Hard

50 mins

Overlapping ABBA

Easy

10 mins

Minimum Jumps

Moderate

25 mins

Best Time to Buy and Sell Stock

Moderate

20 mins

Rod cutting problem

Moderate

40 mins

Merge Two Sorted Arrays

Moderate

15 mins

Majority element

Easy

15 mins

Problem

Submissions

46

Avg. time to solve

25 min

Success Rate

75%

Problem Statement

```
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains a positive integer N, which represents the number of shops.
The next line contains 'N' single space-separated positive integers representing a constant given for each shop.
```

```
For each test case, print the minimum number of jumps or -1, if it is impossible to reach the last shop.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 5 * 10^4
0 <= Arr[i] <= N
Where T is the number of test cases, N is the size of the array and Arr[i] is the ith element in the array.
```

```
2
5
2 1 3 2 4
3
3 2 1
```

```
2
1
```

```
In the 1st test case, Bobs jumps from shop 0 to shop 2 and then jumps from shop 2 to shop 4, so he needs two jumps to reach the last shop.
In the 2nd test case, Bobs jumps from shop 0 to shop 2, so he needs only one jump to reach the last shop.
```

```
2
5
1 0 3 2 1
4
1 1 1 1
```

```
-1
3
```

Java (SE 1.8)

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Theme

Solution submission not allowed

Save Code

Reset Code