To the Top
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 | 231 Views, 23121 Search Bots | 126 Words

Subscribe to Feed Burner | 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:


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?
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 231 Views, 23121 Search Bots | 126 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Sort Colors
  2. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
  3. Daily Interview Problem: Queue Using Two Stacks
  4. Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
  5. Daily Interview Problem: Spiral Traversal of Grid
  6. [Daily Problem] Longest Palindromic Substring
  7. Daily Interview Question: Word Search
  8. Daily Interview Puzzle: Falling Dominoes
  9. Daily Interview Problem: Merge List Of Number Into Ranges
  10. Daily Interview Problem: Room scheduling

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />