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 | 493 Views, 26139 Search Bots | 69 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 493 Views, 26139 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 | 493 Views, 26139 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 Problem] Add two numbers as a linked list
- Daily Interview Question: Find Cycles in a Graph
- Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
- PHP Unit Tests on VPS Server
- A trick for getting good at coding interviews FASTER
- Daily Interview Problem: Queue Using Two Stacks
- Daily Interview Problem: Reverse Words in a String
- [Daily Problem] Longest Increasing Subsequence
- Batch Programming in XP
- ImageMagick Vulnerabilities - CVE-2016–3714
©2006~2024 SteakOverCooked - 0.00823 Seconds(s) - 6537.913 KB/s - 35 Online Memory: 529.16 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 !