Longest Consecutive Sequence - Leetcode 128 - Hashmaps & Sets (Python)

preview_player
Показать описание


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

IMPORTANT FIX - WE SHOULD LOOP THROUGH THE SET S AND NOT NUMS ON LINE 5!!!

GregHogg
Автор

Interesting, my thought would be to remove elements from the set each time it was part of a sequence. Yours is likely more elegant since it doesn't mutate the set.

SamuelSandeen
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Holy cow! Aren't there Sr SE who'd architect the software? Why make us do things like this. I know people who never majored in CS and are Software Engineers. Unbelievable

hlubradio
Автор

Very nicely done. You should be a college professor but most of them are cocky bastards anyway.

hlubradio
Автор

Thank you for the explanation.
I'm not sure if I understand it correctly, but I think the time complexity is not O(n) but O(n^2), since we have 2 loops.
The while loop makes the solution O(nk), where k is the average consecutive sequence's length. In the worst case, it's O(n^2), when all n elements construct an n-length consecutive sequence.
How do you think?

chungt
Автор

Prof Singh Gupta. First day of class. Hi students! Are you smarter than me? If not you'll be in hell in my class. If you are you can be my student. What the f!

hlubradio