Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!