Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda