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 | 489 Views, 24842 Search Bots | 51 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 489 Views, 24842 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 | 489 Views, 24842 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
- Algorithm Interview: Level Order Traversal of Binary Tree
- Daily Interview Problem: Merge Overlapping Intervals
- Windows Scripting
- Daily Interview Question: Edit Distance
- Palindrome Integers
- Algorithm Interview: Determine If Linked List is Palindrome
- Generate All IP Addresses
- Find Pythagorean Triplets
- Algorithm Interview: Maximum Path Sum in Binary Tree
- Reverse a Directed Graph
©2006~2024 SteakOverCooked - 0.01155 Seconds(s) - 4680.127 KB/s - 12 Online Memory: 516.68 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 !