longest common substring ,giving error why?
import java.util.Arrays; public class Solution { public static int lcs(String str1, String str2){ int dp[][]=new int [str1.length()][str2.length()]; for(int r[]:dp){ Arrays.fill(r, -1); } return helper(0,0,str1,str2,0,dp); } public static int helper(int i,int j,String s1, String s2,int currentlength,int dp[][]){ if(i>=s1.length()||j>=s2.length()) return currentlength; if(dp[i][j]!=-1) return dp[i][j]; int pick=0; if(s1.charAt(i)==s2.charAt(j)) pick= helper(i+1, j+1, s1, s2,currentlength+1,dp); int notpick=Math.max(helper(i+1, j, s1, s2, 0,dp), helper(i, j+1, s1, s2, 0,dp)); dp[i][j]= Math.max(currentlength, Math.max(pick, notpick)); return currentlength=dp[i][j]; } }