Skip to content

Commit cfd01e6

Browse files
Solved problems
1 parent 30ab3a3 commit cfd01e6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ My accepted leetcode solutions to some of the common interview problems.
277277
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) [Smallest Sufficient Team](problems/src/dynamic_programming/SmallestSufficientTeam.java) (Hard)
278278
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) [Stone Game IV](problems/src/dynamic_programming/StoneGameIV.java) (Hard)
279279
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) [Tallest Billboard](problems/src/dynamic_programming/TallestBillboard.java) (Hard)
280+
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) [Count Different Palindromic Subsequences](problems/src/dynamic_programming/CountDifferentPalindromicSubsequences.java) (Hard)
280281

281282

282283
#### [Greedy](problems/src/greedy)

problems/src/dynamic_programming/CountDifferentPalindromicSubsequences.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,29 @@
22

33
import java.util.Arrays;
44

5-
/** Created by gouthamvidyapradhan on 10/04/2021 */
5+
/**
6+
* Created by gouthamvidyapradhan on 10/04/2021 Given a string S, find the number of different
7+
* non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7.
8+
*
9+
* <p>A subsequence of a string S is obtained by deleting 0 or more characters from S.
10+
*
11+
* <p>A sequence is palindromic if it is equal to the sequence reversed.
12+
*
13+
* <p>Two sequences A_1, A_2, ... and B_1, B_2, ... are different if there is some i for which A_i
14+
* != B_i.
15+
*
16+
* <p>Example 1: Input: S = 'bccb' Output: 6 Explanation: The 6 different non-empty palindromic
17+
* subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'. Note that 'bcb' is counted only once, even
18+
* though it occurs twice. Example 2: Input: S =
19+
* 'abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba' Output: 104860361 Explanation:
20+
* There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 10^9
21+
* + 7. Note:
22+
*
23+
* <p>The length of S will be in the range [1, 1000]. Each character S[i] will be in the set {'a',
24+
* 'b', 'c', 'd'}.
25+
*
26+
* Solution: O(N ^ 2) x 4
27+
*/
628
public class CountDifferentPalindromicSubsequences {
729
public static void main(String[] args) {
830
System.out.println(

0 commit comments

Comments
 (0)