To the Top
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 | 245 Views, 22335 Search Bots | 69 Words

Subscribe to Feed Burner | 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.


def longest_consecutive(nums):
# Fill this in.

print longest_consecutive([100, 4, 200, 1, 3, 2])
# 4


Can you do this in linear time?
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 245 Views, 22335 Search Bots | 69 Words Subscribe to Feed Burner

Related Articles

  1. Windows Scripting
  2. [Daily Problem] Remove k-th Last Element From Linked List
  3. Print a tree level-by-level, with line-breaks
  4. 56 Bytes
  5. Consecutive Ones
  6. Longest Substring Without Repeating Characters
  7. Daily Interview Problem: Longest Substring With K Distinct Characters
  8. Algorithm Interview: String Compression
  9. Daily Interview Question: Find Cycles in a Graph
  10. Daily Interview Problem: Merge K Sorted Linked Lists

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">