Question

I am having difficulty in printing the longest common substring in a suffix tree.I can easily calculate the length of the longest common substring but having problems in actually finding the substring.Below is the code for Longest Common Substring in C++.Can anyone please help me out?

Was it helpful?

Solution

Add variable:

int start = -1;

Replace:

ans=max(ans,l);

with:

if (l > ans) {
  ans = l;
  start = i;
}

The longest substrings starts at b[start], so to print the longest substring in the end:

printf("%.*s", ans, b + start);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top