I think your solution takes O(n log n) time due to the sort(). The requirement in question clearly mentions constraint of O(n) time.
Hey here’s o(n), go through list and put everything into Set. Finally go through list again with as curnum and check if previous number i.e curnum - 1 exists in set or not. If it exists then continue to next number i.e curnum+1 as curnum else if it prevnum doesn’t exist that marks as start of a new sequence. Use another loop let’s call it sequence length counting loop inside to check till what point curnum+1 exists in set. This way, for example given in video the sequence counting loop will execute only for 100, 200, and 1 where total number of iterations will still be 6 i.e total elements count.
Wait a sec. I thought we have to find the sequence in the list without sorting it first
Follow me on LinkedIn, I accept every connection!
As someone who has just started getting into programming, your videos are super great! I specifically like these noob vs pro programmer ones, because it shows the way I think (noob) and also how I can improve my thought process to write more efficient code (pro). I don’t think I’d be able to get that “pro” perspective otherwise, so thanks!
I needed a couple of weeks to understand LCS.
Every time i see i realise i code like a noob programmer 😭😭
It’s good for new programmers to learn the basics, but it is hardly use in real life
This was one those problems, i thoroughly enjoyed solving it.
Bruh i'd just throw a hashmap on it 😂😂
Damn dude you make every so simple. I gotta take the time to implement some of these
Cycle sort will give ans in n complexity easily
I wondered how were you able to solve it in 3 seconds.
Interview questions like this are stupid, never in my 8 years programming professionally have I ever run into any problem like this leetcode style nonsense
what us the site of the challenges? leetcode?
Not the animated mouth movement 😭
Solved it in O(n) in abt 2 mins
just did the noob one last night :(
I can't find the link to the solution
@GregHogg