Longest Substring Without Repeating Characters (Leetcode 3) - Medium (Hindi)

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ม.ค. 2025

ความคิดเห็น • 68

  • @ShariquaSuman
    @ShariquaSuman 3 หลายเดือนก่อน +3

    After spending 4hours in depression for understanding this concept, finally landed here...crisp and clear!

  • @shreyasmante8914
    @shreyasmante8914 10 หลายเดือนก่อน +2

    excellent !!! 5 min mei samj gya

  • @dhruvinchawda439
    @dhruvinchawda439 4 หลายเดือนก่อน +2

    for me no one explained this question better than you!

  • @batataphotography1479
    @batataphotography1479 ปีที่แล้ว +4

    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

  • @Divyansh-x7n
    @Divyansh-x7n ปีที่แล้ว +2

    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*...

  • @satyanarayanmohanty3415
    @satyanarayanmohanty3415 3 ปีที่แล้ว +3

    Brilliant explanation as always.

  • @magic.pencil2.0
    @magic.pencil2.0 2 ปีที่แล้ว +1

    Greate Explanation in one pass only I understood all thanks bro!!!!

  • @krishnar9932
    @krishnar9932 ปีที่แล้ว +1

    Nice explanations

  • @market_advice266
    @market_advice266 3 ปีที่แล้ว +2

    Very good video. Please continue the great work..

  • @sanjayachari-c5u
    @sanjayachari-c5u หลายเดือนก่อน

    very good explainetion

  • @davidwarner325
    @davidwarner325 2 ปีที่แล้ว +1

    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
      @subirkumar6786 2 ปีที่แล้ว

      but i think now runtime increases

  • @pg-hq4dm
    @pg-hq4dm 5 หลายเดือนก่อน

    actually a great explanation

  • @user-mm6xx1oq9v
    @user-mm6xx1oq9v 4 หลายเดือนก่อน +1

    Here is my solution without using 2nd while loop :
    class Solution {
    public int lengthOfLongestSubstring(String s)
    {
    int right=0,left=0;
    Setst = new HashSet();
    int max=0;
    while(right

  • @HomesickCoder
    @HomesickCoder 2 ปีที่แล้ว +1

    brilliant explanation bhaiya

  • @GhostRider....
    @GhostRider.... 2 ปีที่แล้ว +1

    Nice Explanation bhai

  • @mr.mohitrathore9263
    @mr.mohitrathore9263 3 ปีที่แล้ว +1

    Really help full sir

  • @abhinaybelde8233
    @abhinaybelde8233 2 ปีที่แล้ว +1

    best video so far!!

  • @sagarzambre7205
    @sagarzambre7205 2 ปีที่แล้ว +1

    Well explained..🙌

  • @akhandpratapsingh2814
    @akhandpratapsingh2814 3 ปีที่แล้ว +1

    Good work 👍

  • @ShubhamSingh-jx1ip
    @ShubhamSingh-jx1ip 11 หลายเดือนก่อน

    Your explanation is tooo good sir thank you 😊

  • @AmiMish0909
    @AmiMish0909 3 ปีที่แล้ว +1

    Great content

  • @RavinderSingh-nh6th
    @RavinderSingh-nh6th ปีที่แล้ว

    very nice explanation. Thanks

  • @dhavalpatel4603
    @dhavalpatel4603 8 หลายเดือนก่อน +1

    What's substring of dvdf?

  • @tilakrajchoubey5534
    @tilakrajchoubey5534 3 ปีที่แล้ว +2

    Do we really need nested while loop?

  • @NinjaCoders
    @NinjaCoders ปีที่แล้ว

    Awesome video, please keep it up.

  • @CDACCCEE
    @CDACCCEE 9 หลายเดือนก่อน

    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

  • @umeshnaik844
    @umeshnaik844 ปีที่แล้ว

    Best explanation

  • @kbarot3886
    @kbarot3886 ปีที่แล้ว +1

    Please do a video for Longest Repeating Character Replacement also

  • @srinivaskonduri7496
    @srinivaskonduri7496 3 ปีที่แล้ว +2

    Very good video. Please continue the great work sir...

  • @MOD_Podcast_
    @MOD_Podcast_ 7 หลายเดือนก่อน

    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;
    }
    }

  • @techie_bhuvi
    @techie_bhuvi 3 ปีที่แล้ว +2

    Although explanation is good but there is one correction brute force approach time complexity would be 0(n3)

    • @CodingWithPrakash_
      @CodingWithPrakash_  3 ปีที่แล้ว

      I guess yes , if he consider substring function complexity

  • @akshaygoyal4118
    @akshaygoyal4118 10 หลายเดือนก่อน

    function getLongestSubstring(str){
    let arr = str.split("");
    let maxRes=''
    let start =0;
    let hashMap = new Map()
    for(let end =0; end < arr.length; 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 < mystring.length){
    maxRes = mystring
    }
    }
    return maxRes
    }

  • @tricksforsolving2804
    @tricksforsolving2804 4 หลายเดือนก่อน

    If want to print the longest string then how it will with given code

  • @Ajaykumar-hy2wm
    @Ajaykumar-hy2wm ปีที่แล้ว +1

    Bro please upload your upcoming videos in English

  • @saurabhshiradkar
    @saurabhshiradkar ปีที่แล้ว

    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 < s.length()) {
    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;
    }

  • @rohandebnath3251
    @rohandebnath3251 ปีที่แล้ว

    Hey
    class Solution {
    public int lengthOfLongestSubstring(String s) {
    Set st=new HashSet();
    int left=0;
    int right=0;
    int max=0;
    while(right

  • @PiyushKumar-wh8oh
    @PiyushKumar-wh8oh 3 ปีที่แล้ว +2

    1st View 1st Comment 🎈

  • @nmaajidkhan
    @nmaajidkhan 2 ปีที่แล้ว +1

    workable c++ easy solution:
    class Solution {
    public:
    int lengthOfLongestSubstring(string s) {
    unordered_set Set;
    int left=0, right=0, maxlen = 0;
    while(right < s.size()){
    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;
    }
    };

  • @rishabhrathore8979
    @rishabhrathore8979 2 ปีที่แล้ว +1

    Check time complexity?

  • @alpha3491
    @alpha3491 3 ปีที่แล้ว +11

    If possible use cpp, most of the people prefer that for cp over any other language...btw nicely explained👍

    • @thelazymim9338
      @thelazymim9338 2 ปีที่แล้ว +7

      Sorry Not Most People. Java syntax is easily readable.

    • @Coding-Just
      @Coding-Just ปีที่แล้ว +1

      @@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
      @kidoo1567 ปีที่แล้ว +1

      No no Java

  • @moinakram4610
    @moinakram4610 3 ปีที่แล้ว +1

    Hello I need help here
    YOur return the length here , but if we want the string how should we take

    • @CodingWithPrakash_
      @CodingWithPrakash_  3 ปีที่แล้ว

      Join discussion grp

    • @world4376
      @world4376 2 ปีที่แล้ว +2

      return the HashSet object but again the function return type should change to HashSet from int.

  • @harshalbhagat7669
    @harshalbhagat7669 ปีที่แล้ว

    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.

    • @TarunAnandGoyal
      @TarunAnandGoyal ปีที่แล้ว +1

      because we have to find substring not subsequence. substrings are continuous while subsequence may not

  • @praveentakpuriya5431
    @praveentakpuriya5431 3 ปีที่แล้ว +1

    isko stack se bhi kr sakte hai??

    • @CodingWithPrakash_
      @CodingWithPrakash_  3 ปีที่แล้ว +1

      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

  • @manavneekhra4901
    @manavneekhra4901 3 ปีที่แล้ว +1

    time complexity O(n) nahi ho sakti aise

  • @18ajai
    @18ajai ปีที่แล้ว

    you are using nested while loop. How is time complexity o(n) here. it should be O(n*n)

  • @CodingWithPrakash_
    @CodingWithPrakash_  9 หลายเดือนก่อน

    ✅ Useful Links
    𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - instagram.com/codingwithprakash/
    𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/channel/0029VaACtTa4tRrpDCQc5f44
    𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - www.linkedin.com/in/prakash-shukla/