You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Base Condition: If the starting index exceds the ending index.
if(start>end){
return0;
}
// Initialise count current recursive call
intcount = 0;
// Check if the substring from start to end is valid (i.e ,starts and ends with the same character)
if(s.charAt(start)==(s.charAt(end))){
count=1;
}
// Recursive call for smaller substring by moving the start index to the end index
returncount+ solution(s, start+1, end)
+ solution(s, start,end-1)
- solution(s, start+1,end-1);
// Move start forward:solution(s,start+1,end): This call executes the character at the start position and looks for substring starting from start+1 to end.
// Move end backward: solution(s,start,end-1): This call executes the character at the end position and looks for substring starting from start to end-1;
// Exclude both start and end : solution(s,start+1,end-1):This call excludes both start and end characters and looks for substring starting from start+1 to end-1.