FastPrepNon-decreasing Array

Non-decreasing Array

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Return whether nums can become nondecreasing by modifying at most one element to any integer value.

Function

canBeNonDecreasing(nums: int[]) → boolean

Examples

Example 1

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

Change 4 to 1.

Example 2

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

One change cannot repair both drops.

Constraints

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

More Bloomberg LP problems

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