@@ -0,0 +1,963 @@
+package com.sunny.grokkingalgorithms.fasttrack.dynamicprogrammingandrecursion;%0A%0A/**%0A * Created by sundas on 6/15/2018.%0A */%0Apublic class LongestPalindromicSubsequence %7B%0A%0A  /*%0A  Longest subsequence which is also a palindrome.%0A  BBABCBCAB%0A  longest subsequence = BABCBAB%0A   */%0A%0A  /**%0A   *%0A   * @param s%0A   * @return%0A   */%0A  public static int longestPalindromicSubsequence(String s)%7B%0A    if(s == null%0A        %7C%7C s.length() %3C= 0)%7B%0A      return 0;%0A    %7D%0A    if(s.length() == 1)%7B%0A      return 1;%0A    %7D%0A    if(s.charAt(0) == s.charAt(s.length() - 1))%7B%0A      return longestPalindromicSubsequence(s.substring(1,s.length() - 1)) + 2;%0A    %7D%0A    else%7B%0A      return Math.max(longestPalindromicSubsequence(s.substring(1)),%0A          longestPalindromicSubsequence(s.substring(0,s.length() - 1)));%0A    %7D%0A  %7D%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A     String s = %22BBABCBCAB%22;%0A    System.out.println(longestPalindromicSubsequence(s));%0A  %7D%0A%0A%7D%0A

Longest palindromic sequence recursive solution 2.pow(n)