← 返回 amazon 的题目列表Convert Array to Non-decreasing Array by Adding x
类型:online_judge
Convert Array to Non-decreasing Array by Adding x
Given an integer array arr, you can place an integer x at any position in the array. Your task is to convert the array into a non-decreasing array. Please return the minimum x needed to make the array non-decreasing.
Input
An integer array arr with length range [1, 10^5].
Output
Return an integer representing the minimum x needed.
Example
Input: [3, 1, 4, 2]
Output: 3
Input: [1, 2, 3, 4]
Output: 0
Example
Input
1
3 1 4 2