页面顶部 Top
文件:  root - text - article - 2019 - 10 - non-decreasing-array-with-single-modification.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 232 次阅读, 23205 次搜索 | 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:


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?
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 232 次阅读, 23205 次搜索 | 126 个单词 定阅此目录的博客

猜您喜欢...

  1. How to Play WAV music under DOS?
  2. Daily Interview Problem: Merge List Of Number Into Ranges
  3. Daily Interview Problem: Buddy Strings
  4. [Daily Problem] Witness of The Tall People
  5. Two Tricks of Delphi
  6. 56 Bytes
  7. Daily Interview Problem: Decode String
  8. Daily Interview Question: Word Search
  9. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  10. Staying on a Chess Board

评论 (0)

您的邮件 (不公开域名部分):

您的评论:

悄悄话(发邮件) 颜色 更多笑脸 S x y @

验证码 (点击图片更新):

    当前页暂时没有评论。


最后更新: October 30 2020 14:21:12 | RSS Subscription
牛排怎么做才好吃? | <meta name="机器人" content="不索引, 跟踪" />