I have been trying this problem, i came up a solution but it seems to work on only the same input given. Below is my recursive approach
prinmax(arr,0,1,n,0)
public static int prinmax(char arr[],int beg,int end,int n,int k){
if(end==n)
return 0;
if(beg>=end)
return 0;
if(k==0) {
if(s==1)
return 1;
s=1;
}
if(arr[beg]=='(')
k++;
if(arr[beg]==')')
k--;
int ans=0;
ans=Math.max(ans,prinmax(arr,beg,end+1,n,k)+prinmax(arr,beg+1,end,n,k));
return ans;
}
please tell me the correct recursive approach for this problem