Longest Consecutive Sequence | Leetcode 128 | Hashset

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

Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)

#leetcode
#leetcodeJuneChallenge
#interviewpreparation
Longest Consecutive Sequence Leetcode
Longest Consecutive Sequence C++
Longest Consecutive Sequence C++ Hindi
Longest Consecutive Sequence Hindi

Checkout the series: 🔥🔥🔥
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
Рекомендации по теме
Комментарии
Автор

I am a tamil guy... but I understood the concept. Thank you once again ayusi..

Darshan-prk
Автор

Mam, in the code it is seen that a 'while' loop is used inside a 'for' loop. Won't the time complexity become order of n square??

meb
Автор

Great explanation even it is better than striver's explanation.

yt_goluyadav
Автор

your solution is great
goood approach

sathyamantri
Автор

10:13 O(n) for traversing element and O(log n) for find element so time complicity O(n*log n) I am right or wrong any one suggest.

TodayContestSolution
Автор

Now question level is chnaged from HARD to MEDIUM. Using int for count and current is giving TLE. We have to use long instead.

d_codergaming
Автор

Mam, what will be time complexity for this test case [3, 2, 1, 1, 1, 1, 1, 1, 1, 1] & your code is giving 1000+ runtime but this code is faster as compared to the code shown in video .

class Solution {
public:
int nums) {

int n=nums.size();
unordered_set<int> st;

for(int i=0;i<n;i++){
st.insert(nums[i]);
}

int maxi=0;

for(auto i:st){

if(st.count(i-1))continue;
int len=1;

while(st.count(i+len))len++;

maxi=max(maxi, len);
}
return maxi;

}
};
Both codes will take O(N) time, but why runtime difference is so huge?

software
Автор

nice explaination totally loved it, a big shoutout to youu miss😄

aayushreejaiswal
Автор

class Solution {
public:
int nums)
{
unordered_set<int> st;
for( auto ele : nums ) st.insert( ele );
int ans = 0 ;
for( auto ele : nums )
{
if( st.find( ele - 1 ) == st.end() )
{
int len = 0 ;
while( st.find( ele ) != st.end() )
{
ele++;
len++;
}
ans = max( ans, len );
}
}
return ans;
}
};

saivardhanpallerla
Автор

Why cant we use a simple set and check the difference of adjacent elements if the difference is one then the count will be incremented please answer..!

Star_Bawa
Автор

Aayushi apna phone number do please doubt puchenge

RajeevKumar-fbin