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 | 194 Views, 20582 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 | 194 Views, 20582 Search Bots | 69 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview Question: Find the Single Element in an Array of Duplicates
  2. Algorithm Interview: Convert Roman Numerals to Decimal
  3. Algorithm Interview Question: Nth Fibonacci Number
  4. Algorithm Interview Question: Max and Min with Limited Comparisons
  5. Algorithm Interview: String Compression
  6. Daily Interview Puzzle: Intersection of Linked Lists
  7. Daily Interview Problem: Distribute Bonuses
  8. Algorithm Interview: Longest Consecutive Sequence
  9. Daily Interview Problem: Validate Binary Search Tree
  10. Algorithm Interview: No Adjacent Repeating Characters

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />