1930. Unique Length-3 Palindromic Subsequences - Day 4/31 Leetcode January Challenge

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ม.ค. 2025
  • Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!
    Problem: leetcode.com/p...
    Twitch: / larryny
    Discord: / discord
    Instagram: / larrysomewhere
    #leetcode #coding #programming

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

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

    Were you able to 3 unique this?

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

    I was able to use a two pointer approach. left pointer moves up each iteration. right pointer starts from the end and keeps decreasing until s[left] == s[right]. Then i sliced the string from left+1 to right and added the number of unique character to the count. Since the problem asks for length 3, once we find s[left] == s[right] we know that all the unique characters in the middle will make up palindromes --> s[left] + char + s[right].

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

    need to learn to use bit mask ,never thought of doing that way

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

    I solved it in exact same way and this approach should have been mentioned in the editorial as it is O(n)+O(26*26)~O(n) and space is also constant

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

      editorial solution is also constant space and O(N) time

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

      @ it is O(26*n) which is technically O(n) but this seems to be performing well if your input n is greater than 26

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

    i didnt understand for bit mask but thanks haha