Longest Substring Without Repeating Characters - Leetcode 3 - Sliding Window (Python)

Поделиться
HTML-код
  • Опубликовано: 6 янв 2025

Комментарии • 29

  • @GregHogg
    @GregHogg  5 месяцев назад +2

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @vaibhavchetri8819
    @vaibhavchetri8819 3 месяца назад +1

    Best Explanation. Its Crystal Clear

  • @AvinashKumar-d1i1p
    @AvinashKumar-d1i1p 2 месяца назад

    Best explaINATION ON THIS TOPIC ON YT..

  • @middle-agedclimber
    @middle-agedclimber 7 месяцев назад +5

    Best solution I've seen. Thanks

  • @HussainAli-hn2ef
    @HussainAli-hn2ef 3 месяца назад +1

    great explanation!

  • @HelicopterRidesForCommunists
    @HelicopterRidesForCommunists 5 месяцев назад

    Best solution Ive seen. Nice!

  • @pravuchaudhary3904
    @pravuchaudhary3904 3 месяца назад +1

    I have two questions:
    1. insted of while loop , why not use if...else
    2. after while loop: instead of removing and updating the char in sett, why not add string in sett first and start update "longest"

  • @Jay-zr8kx
    @Jay-zr8kx Месяц назад

    instead of using set, using key value pair object, to track the last index a character is found so that {a:0, b:1, c:2}, then when a second a is found if we update the a index to {a:3, b:1, c:2} then left pointer to original a index +1, are we able to save the extra looping until finding valid substring?

  • @pumpkinp6906
    @pumpkinp6906 10 месяцев назад +4

    Great explanation ! It would be great if you would share the leetcode problem link in description so that we can implement ourselves after learning

  • @kashinathpatekar9870
    @kashinathpatekar9870 10 месяцев назад +4

    Technically the size of the set will be limited by the character set used, so can we call it O(1) space?

    • @GregHogg
      @GregHogg  10 месяцев назад +4

      Oops did I say O(n) space? You're completely correct, yes!

    • @kashinathpatekar9870
      @kashinathpatekar9870 10 месяцев назад

      Thanks for clarifying!

    • @foudilbenouci482
      @foudilbenouci482 7 месяцев назад

      more exactly O(n/c) where c is the capacity of the character set used and n the size of the string

    • @shashank5175
      @shashank5175 4 месяца назад

      @@foudilbenouci482 O(n/c) could be reduced to O(n) or am I wrong cause I thought you can reduce multiplication and division but can reduce addition and subtraction

  • @ryan.aquino
    @ryan.aquino 3 месяца назад +1

    Get the length of the set instead when comparing. Much easier to think intuitively

  • @yuasufhelal7181
    @yuasufhelal7181 5 месяцев назад

    It's a basic one but please I have question what if we use if s(r) in seen willl it be completely wrong but by what sense. Since you were using while.

  • @DamosyTheFreckle
    @DamosyTheFreckle 7 месяцев назад

    Good explanation, thank you!

  • @rajarshibiswas9424
    @rajarshibiswas9424 6 месяцев назад

    i don't know why the code I have written is exactly same instead of set I used hash map should i have used hash set?? is hash map is the main cause of output limit exceeded??

  • @sumeethraikar711
    @sumeethraikar711 3 месяца назад

    set doesnt preserve insertion order. so how removing of elements is working here.?

    • @freshedits8408
      @freshedits8408 3 месяца назад

      They are removing based on the actual character, but not with an index so it is working.

    • @salxs9664
      @salxs9664 Месяц назад

      @@freshedits8408 Can you explain why it's not an index because I see sett.remove(s[l]) and then l += 1 so shouldn't it be removing sett at index 0 and then moving up? This is something that I am confused by as well. When you add items to the set the first item you add doesn't necessarily stay at index 0

    • @freshedits8408
      @freshedits8408 Месяц назад

      @@salxs9664 no,
      here s means string so we are removing a first index of the string
      Suppose if s[l] means "a" which is the first index in the string and we are removing "a" from the set like set.remove("a").
      If the char already exists then we are removing it.
      Every time we remove, we are changing the starting index

    • @salxs9664
      @salxs9664 Месяц назад

      @@freshedits8408 Thank you that explains it!

  • @ParaSteve1985
    @ParaSteve1985 10 месяцев назад

    Hi there, are you still available for 1o1 trainings sessions?

    • @GregHogg
      @GregHogg  10 месяцев назад +1

      Yes, please email greg.hogg1@outlook.com

    • @ParaSteve1985
      @ParaSteve1985 9 месяцев назад

      @@GregHogg done, waiting for your reply.

  • @ohskynyrdlynyrd
    @ohskynyrdlynyrd 11 дней назад

    "When window is valid we move R, when it's invalid we move L". Had to type it to memorize