Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

There are ‘N’ students sitting in a row each having some marks that they have obtained in the previous examinations. You have to find the maximum difference in the position of two students such that the second student has marks greater or equal to the first student. Formerly, You have to find the maximum value of ‘j’ - ‘i’ such that ‘i’ < ‘j’ and arr[ i ] <= arr[ j ].

Note:

```
Return 0, if there are no such two students present.
```

Detailed explanation

```
1 <= T <= 50
2 <= N <= 10000
0 <= arr[ i ] <= 10^5
Where ‘T’ is the number of test cases.
Where 'N' is the number of students in the row and “arr[ i ]” denotes the marks of “i-th” student.
Time limit: 1 sec
```

```
2
3
1 2 3
8
4 3 2 8 1 3 3 3
```

```
2
6
```

```
In the first test case, the students with marks 1 and 3 ( 1<= 3) have the maximum difference between their positions.
In the second test case, the students with marks 3 and 3 ( 3<= 3) have the maximum difference between their positions, 7 - 1 = 6.
```

```
2
2
5 6
2
6 5
```

```
1
0
```

```
In the first test case, the students with marks 5 and 6 ( 5 <= 6) have the maximum difference between their positions.
In the second test case, there are no such students present.
```