Longest Substring Without Repeating Characters (Leetcode 3) - Medium (Hindi)
✅ Useful Links
𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - / codingwithprakash
𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/channel/0029VaAC...
𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - / prakash-shukla
✅ 𝐋𝐞𝐞𝐭𝐜𝐨𝐝𝐞 𝐏𝐥𝐚𝐲𝐥𝐢𝐬𝐭 - • Leetcode solutions
Longest Substring Without Repeating Characters (Leetcode 3)
leetcode.com/problems/longest...
Music Credit
Track: Julius Dreisig & Zeus X Crona - Invisible [NCS Release]
Music provided by NoCopyrightSounds.
Watch: • Julius Dreisig & Zeus ...
Free Download / Stream: ncs.io/InvisibleYO
Пікірлер: 57
✅ Useful Links 𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - instagram.com/codingwithprakash/ 𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/channel/0029VaACtTa4tRrpDCQc5f44 𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - www.linkedin.com/in/prakash-shukla/
Greate Explanation in one pass only I understood all thanks bro!!!!
Very good video. Please continue the great work..
Brilliant explanation as always.
Thanks bro. It is my second day of searching solution of this problem but not able to understand it. you made me understand the logic and thank you for not making your code look fancy*...
@CodingWithPrakash_
9 ай бұрын
Glad it helped
brilliant explanation bhaiya
excellent !!! 5 min mei samj gya
@CodingWithPrakash_
4 ай бұрын
great
Great content
Well explained..🙌
best video so far!!
Really help full sir
Nice explanations
good way to implement the idea, do 1 favour also please explain with dry run also,i was stuck in the last step when Left is at a and we have 2 b remaining
Good work 👍
Nice Explanation bhai
Best explanation
Very good video. Please continue the great work sir...
@CodingWithPrakash_
3 жыл бұрын
Thanks srinivas
great explanation But I coded it it without using second while loop ---------------------------------------- class Solution { public int lengthOfLongestSubstring(String st) { Set s = new HashSet(); int count = 0; int max = 0; int left = 0 ,right=0; while(rightmax){ max=count; } } return max; } }
@subirkumar6786
Жыл бұрын
but i think now runtime increases
class Solution { public int lengthOfLongestSubstring(String s) { int i=0,j=0,max=0; HashSet seen= new HashSet(); //sliding window-first stays,second expands //j is for all distinct charecters while(j
@akshayaswain8402
2 ай бұрын
Very very brilliant answer
What's substring of dvdf?
Please do a video for Longest Repeating Character Replacement also
Do we really need nested while loop?
class Solution { public int lengthOfLongestSubstring(String s) { int left = 0 , right = 0; int maxLen = 0; HashSet set =new HashSet(); while(righttrue maxLen = Math.max(maxLen , right-left+1); right++; }else{ while(set.contains(c)){ set.remove(s.charAt(left)); left++; } } } return maxLen; } }
very nice explanation. Thanks
@CodingWithPrakash_
8 ай бұрын
You are welcome
Your explanation is tooo good sir thank you 😊
@CodingWithPrakash_
3 ай бұрын
Most welcome
Awesome video, please keep it up.
@CodingWithPrakash_
10 ай бұрын
Thanks, will do!
function getLongestSubstring(str){ let arr = str.split(""); let maxRes='' let start =0; let hashMap = new Map() for(let end =0; end if(hashMap.has(arr[end]) && hashMap.get(arr[end]) >= start){ start = hashMap.get(arr[end]) +1 } hashMap.set(arr[end], end); let mystring = str.substring(start, end+1); if(maxRes.length maxRes = mystring } } return maxRes }
Although explanation is good but there is one correction brute force approach time complexity would be 0(n3)
@CodingWithPrakash_
2 жыл бұрын
I guess yes , if he consider substring function complexity
Hey class Solution { public int lengthOfLongestSubstring(String s) { Set st=new HashSet(); int left=0; int right=0; int max=0; while(right
Check time complexity?
Bro please upload your upcoming videos in English
1st View 1st Comment 🎈
@CodingWithPrakash_
3 жыл бұрын
🙂 Thanks piyush
you are using nested while loop. How is time complexity o(n) here. it should be O(n*n)
else { while (seen.contains(c)) { seen.remove(s.charAt(left)); left++; } } in the else part we can use inbuilt contains method of Set Following is the complete code public int lengthOfLongestSubstring(String s) { int left = 0; int right = 0; Set seen = new HashSet(); int max = 0; while (right char c = s.charAt(right); if (seen.add(c)) { max = Math.max((right - left) + 1, max); right++; } else { while (seen.contains(c)) { seen.remove(s.charAt(left)); left++; } } } return max; }
Please anyone can explain this??? Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
@user-hf5bo1mp1c
11 ай бұрын
because we have to find substring not subsequence. substrings are continuous while subsequence may not
Hello I need help here YOur return the length here , but if we want the string how should we take
@CodingWithPrakash_
2 жыл бұрын
Join discussion grp
@world4376
2 жыл бұрын
return the HashSet object but again the function return type should change to HashSet from int.
workable c++ easy solution: class Solution { public: int lengthOfLongestSubstring(string s) { unordered_set Set; int left=0, right=0, maxlen = 0; while(right auto it = Set.find(s[right]); if(it == Set.end()){ if(right-left+1 > maxlen){ maxlen = right-left+1; } Set.insert(s[right]); right++; } else{ Set.erase(s[left]); left++; } } return maxlen; } };
time complexity O(n) nahi ho sakti aise
isko stack se bhi kr sakte hai??
@CodingWithPrakash_
3 жыл бұрын
I think sliding window is the best solution because we are searching substring and we store count in array But try with stack if you can think of solution with it and send it to me
If possible use cpp, most of the people prefer that for cp over any other language...btw nicely explained👍
@thelazymim9338
Жыл бұрын
Sorry Not Most People. Java syntax is easily readable.
@Coding-Just
Жыл бұрын
@@thelazymim9338 yes bro cpp is like all are mixture not easily understandable Java syntax are lengthy but anyone can easily understood what can happen
@kidoo1567
9 ай бұрын
No no Java