How can I improve my code so that there is no timeout(12000ms)? This task -> https://www.codewars.com/kata/551f23362ff852e2ab000037
function longestSli