Unique Length-3 Palindromic Subsequences - Leetcode 1930 - Python

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

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

  • @juanmacias5922
    @juanmacias5922 2 วันที่ผ่านมา +38

    I actually like your dry runs, really helps cement the thought behind the algo!

  • @abdalaaljewarane7951
    @abdalaaljewarane7951 วันที่ผ่านมา +16

    Love the dry runs. Please keep doing them

  • @vague5606
    @vague5606 วันที่ผ่านมา +17

    Please don't stop doing dry runs, it makes the algorithm so much more clearer.

  • @Ahmad-h3z1v
    @Ahmad-h3z1v วันที่ผ่านมา +2

    watching the old video yesterday and barely understanding then watching today and getting it within 5 mins shows how much u improved as a teacher props to u man!

  • @business_central
    @business_central วันที่ผ่านมา +2

    man we love your videos, never worry about the length you always explain the best way.

  • @utkarshsinghchouhan8819
    @utkarshsinghchouhan8819 2 วันที่ผ่านมา +28

    "Back when I was still unemployed"...😂😂😂😂🤣🤣

  • @yusufnzm
    @yusufnzm วันที่ผ่านมา +5

    Dry run is actually very helpful.

  • @ramennudeln247
    @ramennudeln247 วันที่ผ่านมา +1

    The first thing I did was make a prefix tree and dfs, and that basically only worked for the first few cases until it used too much memory.
    Then, I used a default dict to store a tuple with the first and last index of every letter (a-z) (using find and rfind), and made a set of all chars between those two indices, and summed the length of the sets for every pair of indices.

  • @ashwingadve7522
    @ashwingadve7522 วันที่ผ่านมา

    Thanks to you, I was able to solve this question on my own using bit manipulation, because I had watched one of your videos in which you told how to use bit manipulation instead of hashmap to store count of characters.

  • @touhidiutcse
    @touhidiutcse วันที่ผ่านมา +1

    We ❤ dry runs regardless of the length of the video, please keep em!

  • @SonalkumarMandal
    @SonalkumarMandal วันที่ผ่านมา +1

    Loved your dry run part

  • @arunmurugan7093
    @arunmurugan7093 วันที่ผ่านมา +4

    I think that your dry run really helps solidify the understanding of the algorithm as well as helps support the time complexity explanation, so I am not against you doing dry runs for some problems.

  • @NeetCodeIO
    @NeetCodeIO  2 วันที่ผ่านมา +9

    Code solution in other languages: neetcode.io/solutions/unique-length-3-palindromic-subsequences

  • @travian821
    @travian821 วันที่ผ่านมา

    I like that your solutions are simple and just work

  • @yhbarve
    @yhbarve 2 วันที่ผ่านมา

    Watched the old video a couple of hours back. This problem is one of my favourites.

  • @_sf_editz1870
    @_sf_editz1870 วันที่ผ่านมา

    Very good approach thank you man ♂️

  • @kaseynguyen4983
    @kaseynguyen4983 วันที่ผ่านมา +1

    I over thought this problem and wasted like 10 minutes, but took a step back and saw the intuition:
    Find the first and last occurrence of each character in the string.
    Count all unique chars in between them.
    class Solution:
    def countPalindromicSubsequence(self, s: str) -> int:
    m = {}
    for i, char in enumerate(s):
    if char in m:
    m[char][1] = i
    else:
    m[char] = [i, i]
    ans = 0
    for a, b in m.values():
    ans += len(set(s[a + 1: b])
    return ans

  • @SD-vk3ko
    @SD-vk3ko วันที่ผ่านมา

    Best Dry Run

  • @VarshilNarola
    @VarshilNarola 2 วันที่ผ่านมา

    I think we can remove 26 multiplier to n and have exact n by some bitmasking things

  • @bigfool8819
    @bigfool8819 วันที่ผ่านมา

    I still haven't learned any of the data structure stuff. Opening up leetcode makes me feel like an actual ape.

  • @dmitrycx
    @dmitrycx วันที่ผ่านมา +1

    I don't get why we would use a set for left part if we are not searching for a particular element but just reading through every element in it? Wouldn't a simple list suffice?

    • @NeetCodeIO
      @NeetCodeIO  วันที่ผ่านมา +3

      To eliminate duplicates, guaranteeing the loop is O(26)

    • @dmitrycx
      @dmitrycx วันที่ผ่านมา

      @ thanks mate.

  • @Arikaran-x8q
    @Arikaran-x8q 2 วันที่ผ่านมา

    heyy bro ! Solve the leetcode 798 , i want your approach because no one is telling their approach correctly ... could you do ?? we reallyy needed !

  • @theyayaa
    @theyayaa วันที่ผ่านมา

    I found the iterating between first and last indices to be simpler than this approach.

  • @vijethkashyap151
    @vijethkashyap151 วันที่ผ่านมา

    🐐🙇🏻‍♂

  • @sanis85
    @sanis85 วันที่ผ่านมา

    There are solutions in 30ms.. how is this efficient? What are those solutions that run like 50x faster?

  • @thegrassguy2871
    @thegrassguy2871 วันที่ผ่านมา

    Would this be sliding window?

    • @rohithravi6640
      @rohithravi6640 วันที่ผ่านมา

      No i guess, because its a subsequence not subarray

  • @giovannigonzalez6272
    @giovannigonzalez6272 วันที่ผ่านมา

    I have went through 260 problems and still was unable to solve this on my own. I dont even know how one would come up with the intuition to even arrive at this solution. There is no end to when Ill be comfortable solving stuff like this on my own yet :/

  • @travian821
    @travian821 วันที่ผ่านมา

    Does anybody else start with a rather brute force solution and then optimizes from that?

  • @sujayvikramgs8588
    @sujayvikramgs8588 2 วันที่ผ่านมา +2

    0th view

  • @aashishbathe
    @aashishbathe 2 วันที่ผ่านมา +3

    I guess its not exactly O(N), its like 26 * O(N) as there can be upto 26 characters in set, but then it is equal to O(N) itself.

    • @LachlanMartinWasTaken
      @LachlanMartinWasTaken 2 วันที่ผ่านมา

      In regards to time complexity, we are not concerned about the absolute time it takes to process data. What we are concerned about is how much does the time change according to the size of the data. 26 * N is still N because N simply means a linear change.

    • @noahgeller392
      @noahgeller392 2 วันที่ผ่านมา

      @@15ag34 The entire reason big O exists is to talk about performance in a way that ignores constants. More than big O should be considered when caring about performance, but that is a separate issue that should be taught separately. Teaching big O to 'include the constants' inherently doesn't make sense and would lead to more confusion.

    • @michael._.
      @michael._. 2 วันที่ผ่านมา +1

      @@15ag34 since when did we care about real world problems when solving leetcode problems

    • @sophiophile
      @sophiophile วันที่ผ่านมา

      Big O notation ignores constant terms. 1 million * O(n) = O(n). That's the point of the notation.

    • @yusufnzm
      @yusufnzm วันที่ผ่านมา

      Why do we need to multiply by 26? I mean there are 26 characters, but what is the reasoning?

  • @andrewjontry
    @andrewjontry 2 วันที่ผ่านมา

    how does it feel knowing your life's work can be solved with AI?

    • @NeetCodeIO
      @NeetCodeIO  2 วันที่ผ่านมา +21

      Can AI make videos like mine yet?

    • @kaseynguyen4983
      @kaseynguyen4983 วันที่ผ่านมา +2

      ​@@NeetCodeIO and even if it could, Id rather have a concise human explain it rather than a robot .

    • @yusufnzm
      @yusufnzm วันที่ผ่านมา +1

      @andrewjontry bro appreciate this great man's work. no need to hate in the comments.

    • @eznx616
      @eznx616 วันที่ผ่านมา +1

      AI can only solve the questions that are already solved or when they are trivial. Try giving AI Leetcode contest question or any other contest question of decent level and watch it will shit itself.

    • @sophiophile
      @sophiophile วันที่ผ่านมา

      @@eznx616 Actually o3 with high test time compute is a better competition coder than pretty much anyone any of us has ever met, unfortunately.