Question
i have a code which i'm not sure why it's not working, i'm getting an error. my entire code looks like this import java.io.*; class
i have a code which i'm not sure why it's not working, i'm getting an error.
my entire code looks like this
import java.io.*;
class Solution{
int c[][];
String d[][];
int m,n;
Solution(){
c = new int[1000][1000];
d = new String[1000][1000];
}
void solve(String a, String b ){
this.m = a.length();
this.n = b.length();
// As new objects of c and b is already created during constructor call then, we don't have to
// initilialize first row and column, They are already 0.
// b[m+1][n+1]
// Assuming
for(int i =1;i
for(int j = 1;j
if(b.charAt(i-1) == a.charAt(j-1))
{
c[i][j] = c[i-1][j-1]+1;
d[i][j]= "LT";
} else if(c[i-1][j]>=c[i][j-1])
{
c[i][j] = c[i-1][j];
d[i][j]= "U ";
}
else {
c[i][j] = c[i][j-1];
d[i][j]= "L ";
}
}
}
// Printing the result
StringBuffer res = new StringBuffer();
for(int i =0;i
for(int j = 0;j
res.append(c[i][j]+" ");
}
res.append(" ");
}
System.out.println(res);
int l = m, k =n;
while(l if(b.charAt(l-1) == a.charAt(k-1)){ res.setCharAt(l, res.charAt(l)+" "+ d[l-1]); l--; k--; } else if(c[l-1][k]>c[l][k-1]) l--; else k--; } // System.out.println(res.reverse()); } } class GFG { public static void main (String[] args) { Solution s = new Solution(); String x = "BAABCDCA"; String y = "BCAABCDA"; s.solve(x,y); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started