File: root - text - article - 2019 - 10 - non-decreasing-array-with-single-modification.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 538 Views, 31288 Search Bots | 126 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 538 Views, 31288 Search Bots | 126 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Microsoft:
You are given an array of integers in an arbitrary order. Return whether or not it is possible to make the array non-decreasing by modifying at most 1 element to any value.
We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n).
Example:
[13, 4, 7] should return true, since we can modify 13 to any value 4 or less, to make it non-decreasing.
[13, 4, 1] however, should return false, since there is no way to modify just one element to make the array non-decreasing.
Here is the function signature:
Can you find a solution in O(n) time?
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 538 Views, 31288 Search Bots | 126 Words You are given an array of integers in an arbitrary order. Return whether or not it is possible to make the array non-decreasing by modifying at most 1 element to any value.
We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n).
Example:
[13, 4, 7] should return true, since we can modify 13 to any value 4 or less, to make it non-decreasing.
[13, 4, 1] however, should return false, since there is no way to modify just one element to make the array non-decreasing.
Here is the function signature:
def check(lst):
# Fill this in.
print check([13, 4, 7])
# True
print check([5,1,3,2,5])
# False
Can you find a solution in O(n) time?
Related Articles
- [Daily Problem] Validate Balanced Parentheses
- Daily Interview Problem: Jump to the End
- Daily Interview Puzzle: Minimum Size Subarray Sum
- Daily Interview Problem: Buddy Strings
- Print a tree level-by-level, with line-breaks
- Algorithm Interview: Permutations of numbers
- New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
- Consecutive Ones
- [Daily Problem] Add two numbers as a linked list
- Progess made
©2006~2024 SteakOverCooked - 0.0081 Seconds(s) - 2380.627 KB/s - 8 Online Memory: 493.64 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !