Leetcode 3. Longest Substring Without Repeating Characters

Sdílet
Vložit
  • čas přidán 19. 04. 2021
  • Given a string s, find the length of the longest substring without repeating characters.
    Example 1:
    Input: s = "abcabcbb"
    Output: 3
    Explanation: The answer is "abc", with the length of 3.
    Example 2:
    Input: s = "bbbbb"
    Output: 1
    Explanation: The answer is "b", with the length of 1.
    Example 3:
    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.
    Example 4:
    Input: s = ""
    Output: 0
    Link to challenge: leetcode.com/problems/longest...

Komentáře • 70

  • @mappa5431
    @mappa5431 Před 2 lety +25

    Your explanation is the only one that i fully understood out of many videos on CZcams for this leetcode question . Thank you so much! keep up the good work ;)

  • @arshdeep011
    @arshdeep011 Před rokem +8

    underrated channel ,,your code and explanations are always very easy to understand makes a difficult question easy :)

  • @IllIIIIIIllll
    @IllIIIIIIllll Před 2 lety +1

    Thanks🤓, and congrats on reaching 5k subs 🔥.

  • @noober7397
    @noober7397 Před rokem +4

    By far the best explanation of this problem!

  • @11_h_sudhanshukumar22
    @11_h_sudhanshukumar22 Před rokem +1

    Awesome explanation , after spending 2-3hr on yt i found this video. Thanks.

  • @madhabtripathy8691
    @madhabtripathy8691 Před rokem +1

    Your Explanation is so amazing, after understand the approach i am able to solve the question 🙏

  • @apekshashinde8663
    @apekshashinde8663 Před 2 lety

    I have been searching for the best explanation for this problem since 1 month n my search ended unto you...great explanation thankyou soo much...

  • @user-wp9cu5jt8v
    @user-wp9cu5jt8v Před 6 měsíci

    Thank you for the nice explanation the way you explained the problem literally i felt like it was very understable and simple ...hats off to you!!

  • @psychology6131
    @psychology6131 Před 3 měsíci

    after 2 hours your explaination helps me to understand the logic.Many many thanks from my heart

  • @saraswatirathore3933
    @saraswatirathore3933 Před 2 lety +1

    The way you are explaining is amazing .

  • @RISHABHSINGH-zz4ej
    @RISHABHSINGH-zz4ej Před rokem +3

    Indeed you don't have much resourses but still your video content is awesome. Please keep posting such videoes.
    I will definitely like to contribute for your channel whenever i get placed.

  • @Tech-Teal
    @Tech-Teal Před 29 dny

    thank you Alisha for explaining this,literly no one can explian better than you..I have seen many youtubers but you are different ,keep it up..

  • @AbhishekKumar-zl1ho
    @AbhishekKumar-zl1ho Před rokem +10

    14:32 What if the element that has to be deleted is not on s[end]. for example, as on 8:21, end is on a, but we have to delete the b char from the set, how this 14:32 statement is taking care of this case.

    • @Viralmems_xyz
      @Viralmems_xyz Před rokem +1

      because we are not increment the start pointer so again check for start

  • @harish5466
    @harish5466 Před rokem

    Thank you very much.. I finally understood the concept 😊😊

  • @durgeshkushwaha2534
    @durgeshkushwaha2534 Před rokem +1

    Very easy explanation. thank you so much ♥♥

  • @ASHUTOSHSHARMA-us6hd
    @ASHUTOSHSHARMA-us6hd Před 3 měsíci

    i am studying from your channel, you are the only hope for dsa. Thanks for such amazing content

  • @SweetSona-om8mt
    @SweetSona-om8mt Před rokem +1

    your videos are beginner friendly.. thank u

  • @darshankalathiya8667
    @darshankalathiya8667 Před 2 lety +1

    very nice memmmm you are a best teacher .. Thanks For Making Good Contain : )

  • @JackSparrow-yu9ot
    @JackSparrow-yu9ot Před 2 lety

    U are doing great work keep it up 👍

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq Před 7 měsíci

    superb job liked it ur effort really appreciate it.

  • @RAVIKUMAR-ef4wo
    @RAVIKUMAR-ef4wo Před rokem

    good explanation thanks. This is short and crisp to the point. It could have been better if you could explain the intution behind to arrive at the solution.How a candidate can think if he sees similar questions without previously looking at the solution.

  • @saichaithrik7134
    @saichaithrik7134 Před 6 měsíci

    your explanation really helped me solve a lot of leetcode problems thank you madam

  • @googlebaba4045
    @googlebaba4045 Před rokem

    we can also do by using unorder set with less time complexity

  • @lokeshthecodingguy7747

    what is the time complexity of this solution O(N) or something greater than this

  • @pg_Nithian
    @pg_Nithian Před rokem

    Thanks for this video
    you are amazing......

  • @ayushranjan5535
    @ayushranjan5535 Před 2 lety +2

    what is the time complexity in this case

  • @beatsbgmabi2308
    @beatsbgmabi2308 Před 8 měsíci

    thank you very much

  • @rahulgautam6387
    @rahulgautam6387 Před 2 lety

    great explaination by two pointer

  • @mohsinking2002
    @mohsinking2002 Před rokem +2

    Osm
    I was doing mistake while erasing from the set
    But got mistake
    Thank you

  • @ashvinkumhar5819
    @ashvinkumhar5819 Před 2 lety

    great explanation

  • @PIYUSH-lz1zq
    @PIYUSH-lz1zq Před 2 lety

    can you tell me the name of this playlist

  • @shobhitagrawal4901
    @shobhitagrawal4901 Před rokem

    thank you !

  • @ooomr.kibeautifulmiss2754

    I used to think that girls are not good at coding same as driving haha ...
    But you are amazing ...
    Really better than others ... your logics are straight forward and easy to understand ... and you use data structure ...
    Very nice ...
    Love from Delhi ...

  • @nagenHARP
    @nagenHARP Před 5 měsíci

    Good Explanation , all case are not passed not handling if character is in between of set

    • @sanjusingh4842
      @sanjusingh4842 Před 5 měsíci

      The char will be removed until it removes the duplicate element.. Try to run the code bro....

  • @sayedkhalil5996
    @sayedkhalil5996 Před rokem

    great sol thanks Alisha

  • @rkrifat5626
    @rkrifat5626 Před 7 měsíci

    thanks apu💚

  • @hemantvishwakarma8751
    @hemantvishwakarma8751 Před 10 měsíci

    Thanks

  • @reshmaparveen6679
    @reshmaparveen6679 Před 3 lety

    Tq somuch❤️❤️❤️❤️

  • @namratadhobale7051
    @namratadhobale7051 Před 2 lety

    crystal clear

  • @naveenkumarmaddala7830
    @naveenkumarmaddala7830 Před 5 měsíci

    Thanks for the video. Can you share code on Java 8 for longest substring in a given string.

  • @Idukhan-jj9kc
    @Idukhan-jj9kc Před 3 lety

    V good 👍👌👏🙌

  • @arpitasur5785
    @arpitasur5785 Před 2 lety

    you're goooooody good

  • @nil6132
    @nil6132 Před rokem

    How solve in java eclipse

  • @alfabinomial6183
    @alfabinomial6183 Před rokem

    awesome !!!!!!!

  • @SnapSHORT1
    @SnapSHORT1 Před 3 lety

    goddess thanks for help

  • @yahooo4854
    @yahooo4854 Před 3 měsíci

    can anybody explain why we did it==Set.end()

  • @jayeshchaurasiya262
    @jayeshchaurasiya262 Před rokem

    Love uhh mam ❣️

  • @FREEFIREGAMING-vw8ty
    @FREEFIREGAMING-vw8ty Před rokem

    Thank you mam

  • @chanduc2000
    @chanduc2000 Před 8 měsíci

    how are you recording video

  • @satyamgupta6030
    @satyamgupta6030 Před rokem

    ty

  • @bhuppidhamii
    @bhuppidhamii Před rokem

    best exp.

  • @nehasamant7774
    @nehasamant7774 Před rokem

    This code is not working for all the test cases

  • @tusharjeena7081
    @tusharjeena7081 Před rokem

    mam you are awesome

  • @subhradipbarik2032
    @subhradipbarik2032 Před 2 lety

    nice

  • @kanikagola9613
    @kanikagola9613 Před 2 měsíci

    Getting wrong output for string "au".
    It should be 2 but I am getting 3.

  • @rachitbadoni5717
    @rachitbadoni5717 Před 2 lety +1

    ❤❤❤❤

  • @Wepiss
    @Wepiss Před 9 měsíci

    I love you

  • @creationtechz7408
    @creationtechz7408 Před 2 lety +1

    Wow I understand completely.

    • @creationtechz7408
      @creationtechz7408 Před 2 lety

      I thought that it is java until I realized that it is C++, please include C++ in title.

  • @rrichard8719
    @rrichard8719 Před rokem

    This is not a Optimum solution it will be more than O(n)

  • @arpitasur5785
    @arpitasur5785 Před 2 lety

    its time complexity is?

    • @ShivamShukla-op2iq
      @ShivamShukla-op2iq Před 2 lety

      time: O(n)
      space: O(n)
      where n is the no. of characters in the string.

  • @amolnikam1840
    @amolnikam1840 Před rokem

    There is a bug in your code. Please correct that.

  • @OR22
    @OR22 Před rokem

    sol in c#:
    public class Solution {
    public int LengthOfLongestSubstring(string s) {
    int end = 0;
    int start = 0;
    int max = 0;
    HashSet set = new HashSet();
    while(start < s.Length) {
    if(!set.Contains(s[start])) {
    set.Add(s[start]);
    max = Math.Max(max, set.Count);
    start++;
    }
    else {
    end++;
    start = end;
    set.Clear();
    }
    }
    return max;
    }
    }

  • @pg_Nithian
    @pg_Nithian Před rokem

    Arshdeep Singh
    Arshdeep Singh
    2 months ago
    underrated channel ,,your code and explanations are always very easy to understand makes a difficult question easy :)
    Code with Alisha
    Reply
    Satish Gollu
    Satish Gollu
    4 months ago
    Underrated Channel.. The way you explain the concept is simply splendid. Thanks much for your time and effort.
    Code with Alisha
    Reply
    Madhab Tripathy
    Madhab Tripathy
    1 month ago
    Your Explanation is so amazing, after understand the approach i am able to solve the question 🙏
    Code with Alisha
    Reply
    Noober7
    Noober7
    3 months ago
    By far the best explanation of this problem!
    1
    Code with Alisha
    Reply
    Ooo Mr. Ki Beautiful Miss
    Ooo Mr. Ki Beautiful Miss
    5 months ago (edited)
    I used to think that girls are not good at coding same as driving haha ...
    But you are amazing ...
    Really better than others ... your logics are straight forward and easy to understand ... and you use data structure ...
    Very nice ...
    Love from Delhi ...
    1
    Code with Alisha
    Reply
    Saraswati Rathore
    Saraswati Rathore
    9 months ago
    The way you are explaining is amazing .
    Code with Alisha
    Reply
    Sweet. Sona
    Sweet. Sona
    3 months ago
    your videos are beginner friendly.. thank u
    1
    Reply
    Abenezer Getachew
    Abenezer Getachew
    3 months ago
    Your explanation is really good!
    Code with Alisha
    Reply
    11_H_sudhanshu kumar
    11_H_sudhanshu kumar
    1 month ago
    Awesome explanation , after spending 2-3hr on yt i found this video. Thanks.
    Code with Alisha
    Reply
    Apeksha Shinde
    Apeksha Shinde
    6 months ago
    I have been searching for the best explanation for this problem since 1 month n my search ended unto you...great explanation thankyou soo much...
    Code with Alisha
    Reply
    Jack Sparrow
    Jack Sparrow
    7 months ago
    U are doing great work keep it up 👍
    Code with Alisha
    Reply
    Logan
    Logan
    6 months ago (edited)
    Thanks🤓, and congrats on reaching 5k subs 🔥.
    Code with Alisha
    Reply
    Namrata Dhobale
    Namrata Dhobale
    5 months ago
    crystal clear
    Code with Alisha
    Reply
    ayush ranjan
    ayush ranjan
    6 months ago
    what is the time complexity in this case
    1
    Reply
    Ashvin Kumhar
    Ashvin Kumhar
    7 months ago
    great explanation
    Code with Alisha
    Reply
    Rahul Gautam
    Rahul Gautam
    6 months ago
    great explaination by two pointer
    Code with Alisha
    Reply
    GoogleBaba(404)
    GoogleBaba(404)
    2 months ago (edited)
    we can also do by using unorder set with less time complexity
    Reply
    Muhammad Mohsin
    Muhammad Mohsin
    4 months ago
    Osm
    I was doing mistake while erasing from the set
    But got mistake
    Thank you
    Code with Alisha
    Reply
    Darshan Kalathiya
    Darshan Kalathiya
    6 months ago
    very nice memmmm you are a best teacher .. Thanks For Making Good Contain : )
    1
    Code with Alisha
    Reply
    NIThian
    NIThian
    5 minutes ago
    Thanks for this video
    you are amazing......
    Reply
    Alfa Binomial
    Alfa Binomial
    3 months ago
    awesome !!!!!!!
    Code with Alisha
    Reply
    Rishabh Sharma
    Rishabh Sharma
    2 months ago
    Java Code :
    class Solution {
    public int lengthOfLongestSubstring(String s) {

    int end = 0;
    int start = 0;
    int max = 0;

    HashSet set = new HashSet();
    while(start < s.length())
    {
    if(!set.contains(s.charAt(start)))
    {
    set.add(s.charAt(start));
    max = Math.max(max, set.size());
    start++;
    }
    else
    {
    end ++;
    start = end;
    set.clear();
    }
    }
    return max;
    }
    }
    Reply
    Lokesh :The Coding Guy
    Lokesh :The Coding Guy
    6 months ago
    what is the time complexity of this solution O(N) or something greater than this
    Reply
    Idukhan 7239
    Idukhan 7239
    1 year ago
    V good 👍👌👏🙌
    Code with Alisha
    Reply
    PIYUSH
    PIYUSH
    7 months ago
    can you tell me the name of this playlist
    Reply
    Creation Techz
    Creation Techz
    9 months ago
    Wow I understand completely.
    1
    Code with Alisha
    Reply
    1 reply
    Arpita Sur
    Arpita Sur
    5 months ago
    you're goooooody good
    Code with Alisha
    Reply
    Stranger Is Talking
    Stranger Is Talking
    7 months ago
    where did you placed in which company?
    Reply
    SUBHRADIP BARIK
    SUBHRADIP BARIK
    6 months ago
    nice
    Code with Alisha
    Reply
    Reshma Parveen
    Reshma Parveen
    1 year ago
    Tq somuch❤❤❤❤
    Code with Alisha
    Reply
    Rachit Badoni
    Rachit Badoni
    4 months ago
    ❤❤❤❤
    1
    Code with Alisha
    Reply
    Shobhit Vijay
    Shobhit Vijay
    1 year ago
    goddess thanks for help
    Code with Alisha
    Reply
    nil
    nil
    2 months ago
    How solve in java eclipse
    Reply
    Jayesh Chaurasiya
    Jayesh Chaurasiya
    2 months ago
    Love uhh mam ❣
    Reply
    Arpita Sur
    Arpita Sur
    5 months ago
    its time complexity is?

  • @everyone8057
    @everyone8057 Před rokem

    nice