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 | 340 Views, 22171 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 | 340 Views, 22171 Search Bots | 51 Words Subscribe to Feed Burner

Related Articles

  1. Print a tree level-by-level, with line-breaks
  2. [Daily Problem] Course Prerequisites
  3. Find Missing Numbers in an Array
  4. Algorithm Interview: No Adjacent Repeating Characters
  5. Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
  6. Making a Height Balanced Binary Search Tree
  7. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  8. How to Play WAV music under DOS?
  9. Daily Interview Puzzle: Ways to Traverse a Grid
  10. Algorithm Interview Question: H-Index

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: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />