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 | 492 Views, 26133 Search Bots | 69 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 492 Views, 26133 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 | 492 Views, 26133 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
- Reverse a Linked List
- Algorithm Interview: Maximum Path Sum in Binary Tree
- Algorithm Interview: Make the Largest Number
- Reverse a Directed Graph
- Staying on a Chess Board
- Daily Interview Puzzle: Ways to Traverse a Grid
- Delphi Dynamic Array
- Non-decreasing Array with Single Modification
- Daily Interview Puzzle: Intersection of Linked Lists
- Daily Interview Problem: Circle of Chained Words
©2006~2024 SteakOverCooked - 0.00936 Seconds(s) - 2116.007 KB/s - 32 Online Memory: 493.26 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 !