文件: root - text - article - 2019 - 10 - non-decreasing-array-with-single-modification.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 525 次阅读, 29766 次搜索 | 126 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 525 次阅读, 29766 次搜索 | 126 个单词
| 浏览 | 博客存档
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?
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 525 次阅读, 29766 次搜索 | 126 个单词 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?
猜您喜欢...
- Floor and Ceiling of a Binary Search Tree
- Algorithm Interview Question: H-Index
- Daily Interview Problem: Deepest Node in a Binary Tree
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
- Daily Interview Problem: Reverse Integer
- Algorithm Interview: Make the Largest Number
- Spreadsheet Columns
- Sort a Partially Sorted List
- Daily Interview Problem: Arithmetic Binary Tree
- CPU Utilization
©2006~2024 牛排过熟 - 0.0084 秒 - 2379.244 KB/s - 41 在线 内存: 494.1 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
牛排怎么做才好吃? | <meta name="机器人" content="索引, 跟踪">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
评论 (0)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。