MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / recursion

Method recursion

CountPalindromicSubsequences.java:10–23  ·  view source on GitHub ↗
(String str,int start,int end)

Source from the content-addressed store, hash-verified

8
9 }
10 public static long recursion(String str,int start,int end)
11 {
12 // base case
13 if(start>=str.length() || end<0) return 0;
14 // single element is always palindrome
15 if(start==end) return 1;
16 // check twice and subtract
17 else if (str.charAt(start) == str.charAt(end))
18 return recursion(str,start+1, end) + recursion(str,start, end-1) + 1;
19
20 else
21 return recursion(str,start+1, end) + recursion(str,start, end-1) - recursion(str,start+1, end-1);
22
23 }
24
25}

Callers 1

countPSMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected