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

243
Visualizações
How to prevent TLE in Javascript?

I'm solving problems at hackerrank. I've solved some hard problems, but didn't accepted because of TLE.

In Java, BufferReader helps against TLE.

Is there any way in Javascript to prevent TLE?? I've changed my algo few times.. but didn't work. Problem:

For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3. Calculate the sum of similarities of a string S with each of it's suffixes.

My code:

function stringSimilarity(s) {
    // Write your code here
    let myinput = s.split("\n")
    myinput.forEach((elem) => {
        prefcount(elem)
    })
    function prefcount(word) {
        let array = []
        let x
        for(let i = 0; i < word.length; i++) {
            x = word.substring(i)
            array.push(x)
        }
        for(let arr = 0; arr < array.length;){
            let res = 0
            for(let string = 0; string < array[arr].length;) {
                if(array[arr][string] == word[string]) {
                    res++
                    string++
                    arr++
                } else if(array[arr][string] != word[string]){
                     arr++
                }
            }
            array[arr] = res
        }
        console.log(array)
    }

}
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