Is it impossible to use Python for Competitive Programming?

As you can probably assume by the title , i am very new to programming , especially competitive programming. The only language i know right now is Python , and am currently learning Java. So i attempt all of my questions in python only. But the problem i consistently face with it , especially during competitions is TLE. Time Limit Error. I have seen this error so many times now i think i have developed a phobia for it.

Well what should i do? Am i doing something wrong? Maybe my python code is more inefficient than it needs to be? Also ,I dont think you can import libraries like numpy for faster computation , correct me if i am wrong.

A good algorithm will not timeout. If you have used the correct algorithm and your code still times out, then:

@sushmanth_0303 codes in Pypy3, an alternative to Python3. You can refer to his submissions for any tricks in Python. Also, the community here is excellent. You can search on existing topics to learn more about speeding up Python codes.

1 Like

does pypy have the same syntax , and if not does it have a steep learning curve

The syntax for both is the same. I am not sure if \text{Numpy} and other 3^{rd} party libraries work on Pypy3.

Most of the time it don’t but there may be some cases where your program will show TLE even if the algorithm is same for the one created in c++ but this happens rarely, I personally use python and you can use functions to speed up the algorithm a bit and simply some of the operation for better speed.

I think it has lower time limit , same algorithm as above btw

Thanks for informing that. Now i can focus on my algorithmic skills than blaming the language

The time complexity of your code must be higher than that of the expected solution. Try optimising your algorithm.

Can you share the question? It will be quick and easy .