FastPrepMonotonic Array

Monotonic Array

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Return whether nums is monotone. It is monotone when it is entirely nondecreasing or entirely nonincreasing.

Function

isMonotonic(nums: int[]) → boolean

Examples

Example 1

nums = [1,2,2,3]return = true

The array is nondecreasing.

Example 2

nums = [1,3,2]return = false

The direction changes.

Constraints

  • 1 <= nums.length <= 10^5.
  • Values are 32-bit signed integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean isMonotonic(int[] nums) {
  // Write your code here.
}
nums[1,2,2,3]
expectedtrue
Checking account…