Preventing of Execution Timed Out | Sololearn: Learn to code for FREE!


Preventing of Execution Timed Out

I'm trying to solve solution "Word Rank". All algorithms work correctly, but if given word has more than 8 letters it terminated in 4-5 seconds with Execution Timed Out. How to prevent it?

12/22/2020 9:44:30 PM

Dmitry Lezin

3 Answers

New Answer


I guess you're making the list of all words. I faced the problem last year, and used a different solution. I can't remember the detail (it's difficult to read a code without comments), but basically I calculated indexes without searching. the code below shows the basic concept. it's ruby code, but the result can help, I hope. edit: sorry, the code was incomplete when I uploaded, but somehow completed (though still not easy to see). important: I calculated indexes when I solved the problem. The purpose of this code is to show what to calculate by the result, not the algorithm/code itself.


explanation: If a code is not simple, its execution speed depends more on the code itself rather than the language, so I guessed that you are making the list of permutations. If we make a list of permutations, it could take time(it took about 5 seconds on my environment). But you can easily figure out how many items are in the list by calculation (it took milliseconds), and I used combinations of those numbers. My code shows how to combine what(though not clear as I intended).


At last I have done a new solution based on your suggestion: calculate rank by the permutation formula, not by generating the full list of it.