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
Were you able to 3 unique this?
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].
need to learn to use bit mask ,never thought of doing that way
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
editorial solution is also constant space and O(N) time
@ 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
i didnt understand for bit mask but thanks haha