Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
longest common substring Multiple Input in JS
function LCSubStr(X, Y) {

    let m = X.length;
    let n = Y.length;


    let result = 0;


    let end;


    let len = new Array(4);
    for (let i = 0; i < len.length; i++) {
        len[i] = new Array(n);
        for (let j = 0; j < n; j++) {
            len[i][j] = 0;
        }
    }


    let currRow = 0;


    for (let i = 0; i <= m; i++) {
        for (let j = 0; j <= n; j++) {
            if (i == 0 || j == 0) {
                len[currRow][j] = 0;
            }
            else if (X[i - 1] == Y[j - 1]) {
                len[currRow][j] = len[1 - currRow][j - 1] + 1;
                if (len[currRow][j] > result) {
                    result = len[currRow][j];
                    end = i - 1;
                }
            }
            else {
                len[currRow][j] = 0;
            }
        }


        currRow = 1 - currRow;
    }


    if (result == 0) {
        return "-1";
    }

    return X.substr(end - result + 1, result);
}

// Driver Code
let X = "GeeksforGeeks";
let Y = "GeeksQuiz";
// function call
document.write(LCSubStr(X, Y));

How can I convert this code for multiple input?

I checked many lcs code but no one works with

ABCQEFDEFGHIJ BCXEFGYZBCDEWEFGHU > EFGH

This one just works good without any problem. I should convert this one for multiple input in Javascript.

Now we have X,Y but it shoulde be with multiple inputs.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda