FastPrepFind Maximum Length of Non-Decreasing Subarray (Part 1)

Find Maximum Length of Non-Decreasing Subarray (Part 1)

Google logoGoogle● EasyNEW GRADPHONE SCREEN

Problem statement

Note 📝 - It has a follow up question called Longest Non Decreasing Subarray Part 2 🦭

Given an array of size N, find the maximum length of non-decreasing subarray.

Function

findMaximumLengthOfNonDecreasingSubarray(arr: int[]) → int

Examples

Example 1

arr = [0, 7, 3, 10, 2, 4, 6, 8, 0, 9, -20, 4]return = 4

The maximum length of non-decreasing subarray is 4, which corresponds to the subarray [2, 4, 6, 8].

Constraints

  • 1 <= arr.length <= 10^5
  • -10^9 <= arr[i] <= 10^9

More Google problems

See Google hiring insights
Saved
public int findMaximumLengthOfNonDecreasingSubarray(int[] arr) {
  // write your code here
}
arr[0, 7, 3, 10, 2, 4, 6, 8, 0, 9, -20, 4]
expected4
Checking account…