File: root - text - article - 2020 - 01 - longest-consecutive-sequence.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 498 Views, 26227 Search Bots | 69 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 498 Views, 26227 Search Bots | 69 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Amazon:
You are given an array of integers. Return the length of the longest consecutive elements sequence in the array.
For example, the input array [100, 4, 200, 1, 3, 2] has the longest consecutive sequence 1, 2, 3, 4, and thus, you should return its length, 4.
Can you do this in linear time?
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 498 Views, 26227 Search Bots | 69 Words You are given an array of integers. Return the length of the longest consecutive elements sequence in the array.
For example, the input array [100, 4, 200, 1, 3, 2] has the longest consecutive sequence 1, 2, 3, 4, and thus, you should return its length, 4.
def longest_consecutive(nums):
# Fill this in.
print longest_consecutive([100, 4, 200, 1, 3, 2])
# 4
Can you do this in linear time?
Related Articles
- Daily Interview Puzzle: Falling Dominoes
- Find Missing Numbers in an Array
- Daily Interview Problem: Circle of Chained Words
- Daily Interview Problem: Largest BST in a Binary Tree
- Daily Interview Problem: Trapping Rainwater
- Daily Interview Problem: Merge K Sorted Linked Lists
- Algorithm Interview Question: Symmetric k-ary Tree
- Daily Interview Problem: Group Words that are Anagrams
- Daily Interview Puzzle: Intersection of Linked Lists
- [Daily Problem] Course Prerequisites
©2006~2024 SteakOverCooked - 0.01598 Seconds(s) - 1194.194 KB/s - 30 Online Memory: 491.35 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 !