Problem 1: Given an array of real number with length (n2 + 1) A: a1, a2, ... , an2+1. Prove that there is either an increasing or a decreasing subarray of A with length (n + 1). Proof: In order to prove the proposition, we just need to prove that th…
Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. The width of such a ramp is j - i. Find the maximum width of a ramp in A. If one doesn't exist, return 0. Example 1: Input: [6,0,8,2,1,5] Output: 4 Explanatio…
B. Array Sharpening time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You're given an array a1,-,an of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1≤k≤…
You are given an m * n matrix, mat, and an integer k, which has its rows sorted in non-decreasing order. You are allowed to choose exactly 1 element from each row to form an array. Return the Kth smallest array sum among all possible arrays. Example…
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n). Example 1: Input: [4,2,3] Out…
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n). Example 1: Input: [4,2,3] Out…