File tree 2 files changed +32
-2
lines changed
2025-01-January-LeetCoding-Challenge
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 6
6
| January 1 | [ 1422. Maximum Score After Splitting a String] ( https://leetcode.com/problems/maximum-score-after-splitting-a-string/ ) | Easy | Solved |
7
7
| January 2 | [ 2559. Count Vowel Strings in Ranges] ( https://leetcode.com/problems/count-vowel-strings-in-ranges/ ) | Medium | Solved |
8
8
| 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 |
10
10
| January 5 | [ ] ( ) | | |
11
11
| January 6 | [ ] ( ) | | |
12
12
| January 7 | [ ] ( ) | | |
40
40
| Level | Problems | Solved | Unsolved |
41
41
| --- | --- | --- | --- |
42
42
| Easy | 1 | 1 | 0 |
43
- | Medium | 2 | 2 | 0 |
43
+ | Medium | 3 | 3 | 0 |
44
44
| Hard | 0 | 0 | 0 |
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments