Quote:
Actually, I don't want to change my code a lot because the algorithm is correct but it is slow.
And there is your problem.
It's not the code that is slow, but the whole way your are doing it - brute force.
The whole idea of code challenges is not to just get it working, but to do it elegantly, so that it isn't a brute force approach.
You need a better algorithm, then better code to implement that.