GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Longest common subsequence

I created this code using dynamic programming approach but the code is not display the result. the code is as follows:

#include <iostream>
using namespace std;

void LCS(int input1[], int input2[], int n, int m) {
    int L[n + 1][m + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0)
                L[i][j] = 0;
            else if (input1[i - 1] == input2[j - 1])
                L[i][j] = 1 + L[i - 1][j - 1];
            else
                L[i][j] = max(L[i - 1][j], L[i][j - 1]);
        }
    }
    int index = L[n][m];
    int lcs[index];
    int i = n, j = m;
    while (i > 0 && j > 0) {
        if (input1[i - 1] == input2[j - 1]) {
            lcs[index - 1] = input1[i - 1];
            i--;
            j--;
            index--;
        } else if (L[i - 1][j] > L[i][j - 1])
            i--;
        else
            j--;

    }
    for (int i = 0; i < index; i++){
        cout << lcs[i];
    }

}
int main() {
    int n, m;
    cin >> n >> m;
    int input1[n], input2[m];
    for (int i = 0; i < n; i++)
        cin >> input1[i];
    for (int i = 0; i < m; i++)
        cin >> input2[i];
    LCS(input1, input2, n, m);
    return 0;
}

The code terminates without showing any result!

I even switched to a different IDE but its the same. What is wrong with this?

asked Sep 26, 2016 by nrb
...