Skip to content

Commit f25b6fe

Browse files
committed
Jan 4
1 parent 1b4208a commit f25b6fe

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

2025-01-January-LeetCoding-Challenge/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| January 1 | [1422. Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string/) | Easy | Solved |
77
| January 2 | [2559. Count Vowel Strings in Ranges](https://leetcode.com/problems/count-vowel-strings-in-ranges/) | Medium | Solved |
88
| January 3 | [2270. Number of Ways to Split Array](https://leetcode.com/problems/number-of-ways-to-split-array/) | Medium | Solved |
9-
| January 4 | []() | | |
9+
| January 4 | [1930. Unique Length-3 Palindromic Subsequences](https://leetcode.com/problems/unique-length-3-palindromic-subsequences/) | Medium | Solved |
1010
| January 5 | []() | | |
1111
| January 6 | []() | | |
1212
| January 7 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 1 | 1 | 0 |
43-
| Medium | 2 | 2 | 0 |
43+
| Medium | 3 | 3 | 0 |
4444
| Hard | 0 | 0 | 0 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from collections import Counter
2+
3+
4+
class Solution:
5+
def countPalindromicSubsequence(self, s: str) -> int:
6+
freq = Counter(s) # frequency of right string
7+
seen = set() # seen characters of left string
8+
subs = set() # set of palindromic subsequences
9+
for char in s:
10+
freq[char] -= 1
11+
for ch in seen:
12+
if freq[ch] > 0:
13+
subs.add((ch, char)) # same as ch+char+ch
14+
seen.add(char)
15+
return len(subs)
16+
17+
18+
def main():
19+
s = 'aabca'
20+
assert Solution().countPalindromicSubsequence(s) == 3
21+
22+
s = 'adc'
23+
assert Solution().countPalindromicSubsequence(s) == 0
24+
25+
s = 'bbcbaba'
26+
assert Solution().countPalindromicSubsequence(s) == 4
27+
28+
29+
if __name__ == '__main__':
30+
main()

0 commit comments

Comments
 (0)