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 | 514 Views, 27485 Search Bots | 69 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 514 Views, 27485 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 | 514 Views, 27485 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
- Multitasking
- [Daily Problem] Move Zeros
- Algorithm Interview: Determine If Linked List is Palindrome
- Algorithm Interview: Permutations of numbers
- Detect Linked List Cycle
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Generate All IP Addresses
- Maximum In A Stack
- Daily Interview Question: Word Search
- Find the non-duplicate number
©2006~2024 SteakOverCooked - 0.00726 Seconds(s) - 2698.159 KB/s - 12 Online Memory: 493.77 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="index, 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 !