Longest Consecutive Subsequence SOLUTION (Leetcode #128)

preview_player
Показать описание
Longest Consecutive Subsequence SOLUTION (Leetcode #128) // Do you know how to solve this problem?

The longest consecutive subsequence problem on Leetcode (#128) is an interesting coding interview problem that is worth solving as part of your coding interview prep.

Finding the longest consecutive subsequence has been asked at many top tech companies like Google and Facebook, and it demonstrates many coding interview strategies that are valuable to prepare for your interview.

Check out the solution to this coding interview question.

RESOURCES & LINKS MENTIONED IN THIS VIDEO:

YOU CAN ALSO FIND ME HERE

#bytebybyte #leetcode #codinginterview
Рекомендации по теме
Комментарии
Автор

If you're reading this before February 3rd, make sure you sign up for our free masterclass!


ByteByByte
Автор

This turns into O(n^2) when there are a lot of sequences in the input. For example: [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 21] There are 7 different sequences in this small example. This turns into O(n^2) when the input is massive and follows this pattern.

WowPlusWow
Автор

Very few people upload videos on hard leetcode problems. So before watching the video, you already have your like.

darod
Автор

Shouldn't the brute force complexity be something like n^n (something like n! ) ?

OmkarHande
Автор

Because each number will at most be visited twice (first time is the outer loop, second time is the loop by the lowest consecutive element), so the time is O(2n) = O(n)

liwaiyip
Автор

veryy good explanation... This was LC hard.. but you made it like LC easy!

garimasarangal
Автор

Fantastic walk-through of Leetcode #128. BUD optimization ftw!

CostaKazistov
Автор

ordered set takes O(logn) time for searching an element so i think it's time complexity is more than O(n)

SurajSingh-dint
Автор

but lets say we have [8, 7, 6, 5, 4, 3, 2, 1] (the lesser number at last) then it would still be n square, no?

tabeliacosta
Автор

I don't think that even if you sort this u can get the solution in O(nlogN) the reason being take the test case[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6] after sorting [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6]. Now you will need O(N^2) to get the longest consecutive sequence using DP.

apoorvkrishna
Автор

Thanks! Your video could help me study algorithms as well as English. Hope everything goes well

DC-glkb
Автор

Could you please suggest any courses to refer for interview

raghuhck
Автор

Great explanation, keep it up bro! :)

dheerajjodha
Автор

why you haven't coded the solution? please code them like you were doing previously

u_miykykc
Автор

I’m assuming: sort then do some binary search for next number

brianramaswami
Автор

When you wing the Brute Force complexity analysis.

NitishUpreti
Автор

using the same logic but manipulating the set to get max length :

mramit