To the Top
File:  root - text - article - 2020 - 02 - sort-a-partially-sorted-list.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 282 Views, 21306 Search Bots | 93 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Uber:

You are given a list of n numbers, where every number is at most k indexes away from its properly sorted index. Write a sorting algorithm (that will be given the number k) for this list that can solve this in O(n log k)

Example:
Input: [3, 2, 6, 5, 4], k=2
Output: [2, 3, 4, 5, 6]
As seen above, every number is at most 2 indexes away from its proper sorted index.

Here's a starting point:

def sort_partially_sorted(nums, k):
# Fill this in.

print sort_partially_sorted([3, 2, 6, 5, 4], 2)
# [2, 3, 4, 5, 6]
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 282 Views, 21306 Search Bots | 93 Words Subscribe to Feed Burner

Related Articles

  1. CPU Utilization
  2. Daily Interview Puzzle: Intersection of Linked Lists
  3. Algorithm Interview: Maximum Path Sum in Binary Tree
  4. Daily Interview Question: Create a Simple Calculator
  5. Absolute Path
  6. Daily Interview Puzzle: Minimum Size Subarray Sum
  7. Staying on a Chess Board
  8. Patterns for breaking down questions you haven
  9. Daily Interview Question: Longest Sequence with Two Unique Numbers
  10. Most Frequent Subtree Sum

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" />