let lonstr = function(s){ if(!s){ return 0; } let start = 0; let end = 0; let maxlength = 0 const unqiueValue = new Set(); while(end < s.length){ if(!unqiueValue.has(s[end])){ unqiueValue.add(s[end]); end++; maxlength = Math.max(maxlength,unqiueValue.size); } else{ unqiueValue.delete(s[start]); start++; } } return maxlength; } console.log(lonstr("abcabcbb")); i have modify the code you and thanks for this tutorial this really help us
Hi @suneja vaiya, as per my understanding your code is not solving problem of “pwwkew”, as the 3rd sequence it will remove the char “p”. so we will loose “p”. If you can please give screenshot for the above example with correct output!!
Akash you are right, this code is incomplete. Ye correct solution nahi hai. 'else' ka logic incomplete hai. Jaise hi ek repeating character milgaya hame wo saare character nikalna padega Set se, from start index until we remove the duplicate character. Below wala asli solution hai. var lengthOfLongestSubstring = function(s) { if(!s) { return 0; } let end=0; let start=0; let max=0; let unique_char_set = new Set(); while(end < s.length) { let c = s[end]; if(!unique_char_set.has(c)) { unique_char_set.add(c); max=Math.max(max, unique_char_set.size); end++; } else { while(unique_char_set.has(c)) { unique_char_set.delete(s[start]); start++ } } } return max; };
@@srujanthegoldenboy ye sahi hain!!!. Good work bro! @suneja vaiya first of all thanks for the great explanation. 1 request hain jab bhi koi leetcode ka solution karte ho na tabhi har ek test case passed, usko dikha do. Nehi to humlog ko sab test ka solition nehi samajh aata.
@@aiyushbedi you are right else ke under wala inner loop ki jaroorat nahi lag raha hai, mein test nahi kar raha hu. So you guys confirm if that works. Either way my solution will still work with same time complexity. Like you said the main video creator didn't explain the logic properly. He should have created proper good edge cases and explained them properly.
The answer is wrong. Your code uniqueCharatcters output is "acb" and not "abc" . And in the example, it is written that it should be a substring and not a subsequence. Please check the output substring in last which comes as acb and not abc in your code.
if we have to print a unique substring not its count then this will not work. because if we take the string ( dbcab ) and if we have to print the unique character it will print only "cab". CORRECT ME IF I AM WRONG.
I think , when it delete "b" but here we update start value does not end value, so while loops continue for end = 4 and the length of s is 5 bcz here we are not minus 1 in length. that's why it add "b" at the position of 4 then end value tobe 5 or while condition ( 5 < 5 ) false and terminate the loop.
Hii I sir I have doubt, jab program else pe aeiga start srif increase hoga 'end' increase hoga nahi , kyun ki bo if condition pe jaega nahi.to end ka position 3 rahega uske bad badhega nahi
Hi Bhaiya, Muze Infosys ka offer latter aya hai, 20 Feb ko Test aur 4 March Interview tha But mene Jan/2022 me bhi test ke liye apply kiya tha,but due to network issue,i was not able to attend this Test To kya ye offer letter valid rahega ,ya badme 6 month ke baad exam dene ke policy ke under muze Fired karenge
Support this video series, not by money,but by sharing it with your friend's circle 🙏
Sir number send mm please
Bhaiya aap bhi bs video dalte raho views and likes to aayenge hi aise content par
Please make more videos on different problems
let lonstr = function(s){
if(!s){
return 0;
}
let start = 0;
let end = 0;
let maxlength = 0
const unqiueValue = new Set();
while(end < s.length){
if(!unqiueValue.has(s[end])){
unqiueValue.add(s[end]);
end++;
maxlength = Math.max(maxlength,unqiueValue.size);
}
else{
unqiueValue.delete(s[start]);
start++;
}
}
return maxlength;
}
console.log(lonstr("abcabcbb"));
i have modify the code you and thanks for this tutorial this really help us
I have one more query why we have written else condition when we are getting unique value by using set
Please complete this series all the way to required concepts and questions for the interviews.
@ajay bhai regularly ese problems ke video upload karte raho..it helps a lot to improve programming logic.
I already solved this one ! Famous Problem DP❤️
how can u increment end value in else case ,buz ur dry run cases is not matching with written code.
yes really not matching with written code ... what are you saying please review your video
Hi @suneja vaiya, as per my understanding your code is not solving problem of “pwwkew”, as the 3rd sequence it will remove the char “p”. so we will loose “p”. If you can please give screenshot for the above example with correct output!!
Hehehe.. I think you haven’t watched complete video 🙂
Akash you are right, this code is incomplete. Ye correct solution nahi hai. 'else' ka logic incomplete hai.
Jaise hi ek repeating character milgaya hame wo saare character nikalna padega Set se, from start index until we remove the duplicate character.
Below wala asli solution hai.
var lengthOfLongestSubstring = function(s) {
if(!s) {
return 0;
}
let end=0;
let start=0;
let max=0;
let unique_char_set = new Set();
while(end < s.length) {
let c = s[end];
if(!unique_char_set.has(c)) {
unique_char_set.add(c);
max=Math.max(max, unique_char_set.size);
end++;
} else {
while(unique_char_set.has(c)) {
unique_char_set.delete(s[start]);
start++
}
}
}
return max;
};
@@srujanthegoldenboy ye sahi hain!!!. Good work bro! @suneja vaiya first of all thanks for the great explanation. 1 request hain jab bhi koi leetcode ka solution karte ho na tabhi har ek test case passed, usko dikha do. Nehi to humlog ko sab test ka solition nehi samajh aata.
@@aiyushbedi you are right else ke under wala inner loop ki jaroorat nahi lag raha hai, mein test nahi kar raha hu. So you guys confirm if that works.
Either way my solution will still work with same time complexity.
Like you said the main video creator didn't explain the logic properly. He should have created proper good edge cases and explained them properly.
I am sorry to say your understanding is wrong. i just tested the code it is accepted and passed all test cases.
brother please continue the series ... my dsa is getting good because of you
great explanation 😍😍😍😍😍😍😍😍
Please continue with series. TH-cam has less video with Javascript DSA
Thank you 😇
please bring more videos on dsa
JavaScript course is usefully
Bhaiya please complete this series ❤
Hi brother how are you 🥰🥰
I'm waiting your DS & algorithms next video.....
Advance thanks for you brother..
I'm from Bangladesh..
pehly mujhay laga ye code sab test cases k lye applicable nai hoga. then i tested and it worked.
please complete this series, sir!
thanks, alot. love from Pakistan
I need to return string as well with max length. Please suggest.
The answer is wrong. Your code uniqueCharatcters output is "acb" and not "abc" . And in the example, it is written that it should be a substring and not a subsequence. Please check the output substring in last which comes as acb and not abc in your code.
bhai bohot badhiya explain ki hai aapne problem bas ek request hai khana please baad me kha liya karo chap chap ki avaz bohot irritating hai
awesome brother ,make more videos like this
Or videos laeye sir DSA par 👍👍🔥
Please make more videos on different problems
make on leetcode or gfg problems tutorial using javaScript
if we have to print a unique substring not its count then this will not work. because if we take the string ( dbcab ) and if we have to print the unique character it will print only "cab". CORRECT ME IF I AM WRONG.
I think , when it delete "b" but here we update start value does not end value, so while loops continue for end = 4 and the length of s is 5 bcz here we are not minus 1 in length. that's why it add "b" at the position of 4 then end value tobe 5 or while condition ( 5 < 5 ) false and terminate the loop.
Bhai please flutter pe video banao, Indian market me flutter ki kya opportunities hain, kya scope h...
Sure
Which language is best to learn dsa, can i used javascript
Bhaiya Denouncing and Throttling ka video kab tk laoge
sir course complete kab hoga apka dsa ka
Please make more video on DSA JS🚀
if we want to return the string , not only length... , how we achieve this
Pls make video for permutations and combinations ..
Please provide some videos for linkedlist, graph, tree etc.
Aur bhi questions kraya plz
Hii I sir I have doubt, jab program else pe aeiga start srif increase hoga 'end' increase hoga nahi , kyun ki bo if condition pe jaega nahi.to end ka position 3 rahega uske bad badhega nahi
First it will remove duplicate char in set when it is in else part and at if it will add it again to the set and then increase the end.
bhai short video rkha kr or thoda jldi bola kr
18:04
What is the only book you recommend for DSA Javascript?
Upload further DSA topics bro
Mai maan gaya vai...!
bhai please complete this series
sir, ap ye kia kha rhe the parhate waqt ? 🙃
bhaiya.. find k largest & kth largest element question pe explaination banaiye..
Thank you for your efforts but you seem a bit confused while explaining the logic after the coding part and the code is incomplete.
bhai array ka length will be number of elements not from the zero
Hi Bhaiya, Muze Infosys ka offer latter aya hai, 20 Feb ko Test aur 4 March Interview tha
But mene Jan/2022 me bhi test ke liye apply kiya tha,but due to network issue,i was not able to attend this Test
To kya ye offer letter valid rahega ,ya badme 6 month ke baad exam dene ke policy ke under muze Fired karenge
Bhaiya please c++ ke sath dsa start Kar do na
bhai ypoutube bhara para hindi mai bs dsa js mai nh hai eslye fav hai
This is totally wrong the value will be ["B"] at the end at the max value will be 3.
golmal
Explained wrong logic when start points to 3
No English?
Bhai tu mt hi bnaya kr ye videos pta ni kya hi h rata hua code likha h bus
The ans is kew not wke
Please complete this series all the way to required concepts and questions for the interviews.
please bring more videos on dsa
please bring more videos on dsa
please bring more videos on dsa
please bring more videos on dsa
please bring more videos on dsa
please bring more videos on dsa
please bring more videos on dsa