βœ…Moving right (Contest)

Moving right (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

Given an array of heights of N buildings in a row. You can start from any building and jump to the adjacent right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make. Input The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height.

Constraints: 1 <= N <= 105 1 <= height[i] <= 109 Output Print the maximum number of jumps you can make. Example Sample Input:- 5 5 4 1 2 1

Sample Output:- 2

Explanation: We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps.

link:https://my.newtonschool.co/playground/code/dg0xiez0elhh/

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        // Your code here
        Scanner sc= new Scanner(System.in);
        int N=sc.nextInt();
        int arr[]=new int[N];
        for(int i=0;i<N;i++){
            arr[i]=sc.nextInt();
        }
        int count=0;
        int curr=arr[0];
        int max=0;

        
        for(int i=1;i<arr.length;i++){
            if(arr[i]<=curr){
                count+=1;
                max=Math.max(max,count);

                curr=arr[i];
                

            }else{
                
                count=0;
                curr=arr[i];
            }
            
        }
        System.out.print(max);

    }
}
```

Last updated