longest common subarray

Solutions on MaxInterview for longest common subarray by the best coders in the world

showing results for - "longest common subarray"
Kevin
12 Feb 2017
1    for (int i = 0; i <= m; i++)
2    {
3        for (int j = 0; j <= n; j++)
4        {
5            // The first row and first column
6            // entries have no logical meaning,
7            // they are used only for simplicity
8            // of program
9            if (i == 0 || j == 0)
10                LCSuff[i][j] = 0;
11 
12            else if (X[i - 1] == Y[j - 1]) {
13                LCSuff[i][j] = LCSuff[i - 1][j - 1] + 1;
14                result = max(result, LCSuff[i][j]);
15            }
16            else
17                LCSuff[i][j] = 0;
18        }
19    }
20    return result;