2
public int countPalindromicSubsequence(String s) {6
char[] chArr = s.toCharArray();8
int[] firstOcc = new int[26];9
int[] lastOcc = new int[26];11
Arrays.fill(firstOcc, -1);12
Arrays.fill(lastOcc, -1);14
for (int i = 0; i < n; i++) {18
if (firstOcc[ch - 'a'] == -1) {19
firstOcc[ch - 'a'] = i;22
lastOcc[ch - 'a'] = i;25
int ans = 0, count = 0;29
// check for each character ( start or end of palindrome )30
for (int i = 0; i < 26; i++) {32
int si = firstOcc[i]; // si - starting index33
int ei = lastOcc[i]; // ei - ending index35
visited = new boolean[26];39
// check for unique charcters ( middle of palindrome )40
for (int j = si + 1; j < ei; j++) {42
if (!visited[chArr[j] - 'a']) {43
visited[chArr[j] - 'a'] = true;