To the Top
File:  root - text - article - 2019 - 10 - sorting-a-list-with-3-unique-numbers.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 283 Views, 20389 Search Bots | 51 Words

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

Given a list of numbers with only 3 unique numbers (1, 2, 3), sort the list in O(n) time.

Example 1:
Input: [3, 3, 2, 1, 3, 2, 1]
Output: [1, 1, 2, 2, 3, 3, 3]


def sortNums(nums):
# Fill this in.

print sortNums([3, 3, 2, 1, 3, 2, 1])
# [1, 1, 2, 2, 3, 3, 3]


Challenge: Try sorting the list using constant space.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 283 Views, 20389 Search Bots | 51 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
  2. CVE-2015-8874 - cPanel EasyApache Vulnerabilities
  3. Sorting a list with 3 unique numbers
  4. Fibonacci coding
  5. Multitasking
  6. Daily Interview Problem: First Missing Positive Integer
  7. Daily Interview Problem: Look and Say Sequence
  8. Invert a Binary Tree
  9. How to Play WAV music under DOS?
  10. Daily Interview Problem: Count Number of Unival Subtrees

Comments (0)

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