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 | 486 Views, 24706 Search Bots | 51 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 486 Views, 24706 Search Bots | 51 Words
| 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]
Challenge: Try sorting the list using constant space.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 486 Views, 24706 Search Bots | 51 Words 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.
Related Articles
- [Daily Problem] Longest Increasing Subsequence
- Daily Interview Problem: Arithmetic Binary Tree
- Plus One
- Delphi Dynamic Array
- Find the non-duplicate number
- Invert a Binary Tree
- Daily Interview Problem: Given two arrays, write a function to compute their intersection.
- Daily Interview Problem: Full Binary Tree
- Daily Interview Problem: Running Median
- Algorithm Interview: String Compression
©2006~2024 SteakOverCooked - 0.00664 Seconds(s) - 2817.833 KB/s - 82 Online Memory: 492.4 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !