I "know" C++, Python and Java. Been using C++ for over 15 years since school for programming contests and work (computational physics), learnt Python later and use it a lot for my work these days (machine learning etc.), and learnt Java in college. Yet I do most of my Leetcode and competitive programming in C++. And to be honest the reason is historical. I started with C++, and the only language that was guaranteed to be allowed in all contests was C++ (Recently learnt that Google FooBar is an exception). With time I got good at quick contest-like coding in C++. So even after learning python, I could do contest stuff like graph algorithms and sieving superfast in C++ almost from muscle memory. The only time I use python in a contest is if I need something like integers beyond 64 bit. I do use stuff like unusual C++ stl containers and algorithms, and make use of the extra speed, but really my experience with C++ is what makes me choose it. And that is what I would suggest for people too. As long as it is not particularly disadvantaged (for gods sake don't use C for example), use whatever language you are fastest coding in and most comfortable reasoning about. But at the same time try to have some basic knowledge about a couple of other languages to use when your goto language is insufficient. Answer from razimantv on reddit.com
๐ŸŒ
Quora
quora.com โ€บ Should-I-begin-with-C++-or-python-in-competitive-programming
Should I begin with C++ or python in competitive programming? - Quora
If you are reading this answers, you are probably beginner in CP or about to start and you must be confused to start with C++ or Python. In most of the competitions C, C++, Java, Python are allowed. In terms of popularity, C++ is ahead of python. ...
๐ŸŒ
Codeforces
codeforces.com โ€บ blog โ€บ entry โ€บ 76738
Why would someone use Python or Java instead of C++ for Codeforces? - Codeforces
Shorter code? I seriously doubt so. At least compare to Java, C++ is shorter. Compared to Python, unless you want to couple everything into one unreadable line, then C++ should not be very longer.
Discussions

Is Python a correct choice of language for Competitive programming?

No because competitive programming often focuses on speed, and python is not a very fast language.

More on reddit.com
๐ŸŒ r/learnprogramming
6
4
August 19, 2015
Which language is better for competitive coding? - general - CodeChef Discuss
Which language is better for competitive coding? Given I already knew C and Java(only basic) and I code in C. but I am unable to improve performance.Please suggest me language with why that language is good. More on discuss.codechef.com
๐ŸŒ discuss.codechef.com
1
3
July 14, 2014
Python vs C++ for competitive programming?
you have the competition questions. why haven't you tried yourself? More on reddit.com
๐ŸŒ r/learnprogramming
14
1
December 10, 2025
language agnostic - Why do programming competition contestants use C++ and Java? - Stack Overflow
After competing in and following ... and Java. The distribution of languages used throughout the competition can be seen here. After programming in C/C++ for several years, I recently fell in love with Python for its readable/straightforward nature.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/leetcode โ€บ what are your views on c++ vs python (vs java also if you use it) for leetcode and competitive programming?
r/leetcode on Reddit: What are your views on C++ vs Python (vs Java also if you use it) for LeetCode and competitive programming?
September 19, 2022 -

I see this being asked too many times that what is the best language for leetcode and cp. So, I want you to document here your views about which one to prefer and why. I would appreciate views of those people who have good experience with both C++ and Python (or maybe Java) but still prefer one because of some reason. I want you to state those reasons.

This is not about superiority of languages, but only about being suitable to the task at hand.

For me, I mostly use C++ and my reasons are:

  1. Speed obviously. Many times even sub-optimal solution passes the test cases.

  2. Rich set of data structures such as unordered_map (HashMap), unordered_set (HashSet), map (TreeMap), set (TreeSet), stack, queue, deque etc, almost anything you can imagine.

  3. A truck load of algorithms - I know python has very good stuff in itertools and functools but C++'s #include<algorithm> is just another beast. Many leetcode problems become one liner that is readable and can be used even in production code (actually it should be used in production code). Need nth largest or smallest element - std::nth_element, need to merge two sorted ranges - std::merge, need to rotate the array by kth places- std::rotate, want to partition the array - std::partition, want to partition but the initial order is also important - std::stable_partition, want to sort but initial order is also important - std::stable_sort, that's just scratching the surface.

  4. Tail recursion elimination - I can write recursive implementation which is easier to reason about and the compiler will turn it into iterative one for me. SegmentTree and Trie becomes a joke using recursion. Sometimes it really matters, in this weekly contest (Leetcode 311) I solved 4th problem using recursive Trie solution, since I finished before time so thought that I should try it in Python also for practice but I could not get it to accept until I converted everything to iterative.

  5. std::string_view - It makes recursive solutions involving strings really easy - you don't need to copy string so there's no memory penalty and performance penalty. C++20 also has std::span which brings the same ease also to vector and array.

I do come to python for some problems for which my reasons mostly are

  1. DP problems become a joke using lru_cache and cache, actually most of the DP problems I first solve in python, because I can write it like that the maths formula, which helps me figure out what values I need to store in DP table.

  2. The ease of putting anything (constant data structures) into set or map is very convenient as opposed to writing the hash function for std::unordered_map and std::unordered_set.

  3. Arbitrary precision numbers, for problems involving huge numbers there's no better solution that using Python.

Also give response in the poll about which one you use.

Top answer
1 of 3
10
I "know" C++, Python and Java. Been using C++ for over 15 years since school for programming contests and work (computational physics), learnt Python later and use it a lot for my work these days (machine learning etc.), and learnt Java in college. Yet I do most of my Leetcode and competitive programming in C++. And to be honest the reason is historical. I started with C++, and the only language that was guaranteed to be allowed in all contests was C++ (Recently learnt that Google FooBar is an exception). With time I got good at quick contest-like coding in C++. So even after learning python, I could do contest stuff like graph algorithms and sieving superfast in C++ almost from muscle memory. The only time I use python in a contest is if I need something like integers beyond 64 bit. I do use stuff like unusual C++ stl containers and algorithms, and make use of the extra speed, but really my experience with C++ is what makes me choose it. And that is what I would suggest for people too. As long as it is not particularly disadvantaged (for gods sake don't use C for example), use whatever language you are fastest coding in and most comfortable reasoning about. But at the same time try to have some basic knowledge about a couple of other languages to use when your goto language is insufficient.
2 of 3
4
I used to only use Java for LeetCode/CodeForces, but now I have switched to C++ a few weeks ago. I do prefer C++ because Fast input and output are so much easier in C++ than in Java. There is simply no comparison. Java is really wordy, and I hate typing methods such as System.out.println() [I code on Vim w/ no auto completion] C++ has an extensive algo library that is simply unparallel. Also love that I don't have to type map.merge(key, 1, Integer::sum) in Java when in C++ it is just ++mp[key]. Speed. Faster than Java in most cases. No more StringBuilder from Java. s+="a" is O(1). Java does have a few upsides for it of course. Java is more readable to normal folks I think. It is easier to debug Java programs. C++ error messages are usually not as helpful. I think it is easier to parse strings in Java. It has split() for example, whereas in C++ I can only come up with a regex based solution or stringstream. Better docs. This may be subjective but I like IntelliJ IDEA's quick Javadoc. in C++, I have to look it up on cppreference.com As a beginner starting out, I found Java easier to learn, hence that was what I used, but as I become more proficient with Java, I got a bit tired of how wordy Java is and switched to C++. Also, there are some companies OAs that only allow C++ and Python. I don't have much experience with Python. I coded some scripts in them and that's all, but I do remember being annoyed with the indentation.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2808956 โ€บ if-i-already-know-python-should-i-learn-c-for-competitive-programming
If i already know python, should i learn C++ for competitive programming? | Sololearn: Learn to code for FREE!
Although main focus in cp would be on the algorithm that you choose to solve the problem, using C++ sometimes makes it possible to crack some problems with relatively less efficient algorithm because of it's speed. That being said, all the problems are designed in such a way that it should be possible to solve them in the given amount of time in any language that they allow. Some competitions also provide a longer time limit for slower languages like python.
๐ŸŒ
Quora
quora.com โ€บ Is-C-considered-better-than-Python-for-competitive-programming-or-other-tasks-Why-is-Python-currently-more-popular-than-C
Is C++ considered better than Python for competitive programming or other tasks? Why is Python currently more popular than C++? - Quora
Answer (1 of 2): Python is far easier to write the same code in, and far easier to rewrite existing code too. Generally itโ€™s less prone to a whole range of easy to make, hard to debug, often extremely serious, bugs that C++ suffers from.
๐ŸŒ
Codeforces
codeforces.com โ€บ blog โ€บ entry โ€บ 2585
Python vs. C++ - Codeforces
It is a bit unfortunate that a solution to problem D in round-85 (div2) implemented in C++ passes system tests, but same solution implemented in Python times out on test case 40. Does that mean Python isn't a good pick for such time constrained problems?
๐ŸŒ
Medium
medium.com โ€บ @kunemohith โ€บ c-or-python3-for-competitive-programming-8ccbb7285498
C++ or Python3 for Competitive Programming? | by Mohith Kune | Medium
April 10, 2020 - In this case, the C++ program took 30sec which is high but Python3 took 5minutes, which is ridiculous. It is so sad to believe but itโ€™s the truth. Hence, for smaller inputs, Python works fine but for Larger inputs, C++ outperforms Python in time.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-best-suited-competitive-coding
Why is python best suited for Competitive Coding? - GeeksforGeeks
October 4, 2021 - SPEED is a factor where python is second to none. The amount of code to be typed decreases drastically in comparison to conventional programming languages like C, C++, JAVA. Another most important point is that python arms its users with a wide variety of functionality, packages, and libraries that act as a supplement to the programmer's mental ability.
๐ŸŒ
Medium
medium.com โ€บ student-technical-community-vit-vellore โ€บ c-java-or-python-which-language-is-better-for-competitive-coding-4f48063b1a73
C++, Java or Python: which language is better for Competitive Coding? | by Rahul agarwal | Student Technical Community โ€” VIT Vellore | Medium
July 30, 2021 - Being a high level programming language python execution is done using an interpreter unlike other languages which use a compiler, this makes python execution slower as compared to C++ and Java.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ why-cpp-is-best-for-competitive-programming
Why C++ is best for Competitive Programming? - GeeksforGeeks
July 26, 2025 - Widely used: C++ is considered to be the best choice for competitive programming by 75% of the programmers across the world, as it is usually faster than Java and Python and most of the resources are available in C++.
๐ŸŒ
CodeChef Discuss
discuss.codechef.com โ€บ general
Which language is better for competitive coding? - general - CodeChef Discuss
July 14, 2014 - Which language is better for competitive coding? Given I already knew C and Java(only basic) and I code in C. but I am unable to improve performance.Please suggest me language with why that language is good.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ python vs c++ for competitive programming?
r/learnprogramming on Reddit: Python vs C++ for competitive programming?
December 10, 2025 -

have a solid grip on the fundamentals of programming, but I want to delve into competitive programming with the aim of placing highly in British Informatics Olympiad next year. I am aware most competitive programming occurs in C++, but I want to avoid learning syntax and programming all over again, as I am most fluent in python. The main concern that I have is that the programs need to run in under 1 second, which I dont know is possible. Can someone look at a problem from the olympiad and tell me whether python would be suitable, or too difficult : https://www.olympiad.org.uk/papers/2024/bio/bio24-exam.pdf

๐ŸŒ
Turing
turing.com โ€บ kb โ€บ why-is-python-best-suited-for-competitive-coding
Why experts advise learning Python for competitive coding?
Python comes in as the best programming language as it cuts short the time spent writing a code as compared to other conventional languages like Java, C, and C++. Further, the time you save in coding can be utilized to analyze the logic required ...
Top answer
1 of 11
70

Great question! As someone who has dabbled in programming contests a bit myself, I may have something to say.

[Let's get the standard disclaimer out of the way: contest programming is only loosely related to "programming in the real world", and while it tests algorithmic and problem-solving skills and the ability to come up with fast bug-free working code under time pressure, it does not necessarily correlate with being able to build large software projects, write maintainable code, etc (beyond the fact that well-structured programs are easier to debug).]

Now for some answers:

  • C++/Java are more common than other languages in the real world as well, so you'd expect to see a higher proportion anywhere. (But it's even higher in the contest population.)

  • Many of these participants are students, or got into contests as students, and C++/Java are more common "first languages" that students learn. (Undergrad students these days may start with Scheme, Haskell, Python, etc., but high-schoolers (often self-taught) less often.) In fact, many of the Eastern European participants still use Pascal, and are more amazing with it than the rest of us will ever be with any language.

  • The school- and college-level contests usually use these languages. The International Olympiad in Informatics (IOI) allows only C, C++ and Pascal (or maybe it allows Java now; I haven't kept up), and the ACM Intercollegiate Programming Contest (ACM ICPC) allows only C, C++ and Java. TopCoder allows C++, Java, C# and VB (really :p); and recently, Python. So you could say the "contest ecosystem" has more C++/Java programmers in it. Google Code Jam and IPSC are among the few contests that allow code in any language, actually.

  • Now the question is, in GCJ where the contestants are free to choose a language, why wouldn't they choose Python or Scheme? The most relevant factor is that these languages are slow. Sure, for most real-world programming they are easily fast enough, but for the tight loops that are often involved in getting a program to run under the n-second limit for all test cases, these languages don't cut it for any of the algorithmically more involved problems. (A problem designed to accept O(n log n) solutions but not ฮ˜(n2) solutions for C/C++ frequently rules out even optimal O(n log n) solutions in slower languages. Even Java used to be given a handicap at USACO; I'm not sure this is still the case.)

  • Another factor is the libraries: C++ and Java have better libraries for frequently useful algorithms and data structures (e.g. red-black trees, C++'s next_permutation), while Python's libraries (good enough for the real world) are less useful here, and Prolog and Scheme... I don't know about their libraries. This is a relatively minor factor, because these programmers can write their own code when necessary. :-)

  • General-purpose multi-paradigm languages are more useful for just getting things done within the time constraints of the contest, than languages that force a philosophy or way of doing things on you. This is why Prolog will always remain unpopular, for instance. (General philosophy: some languages are "enabling" languages that let you do anything including shooting yourself in the foot, some are "directing" that force you to do things the right way.) This is also why C++ is three times more popular than Java in the general contest participants, and much more popular among the top contestants. Since code doesn't have to be read by anyone else, it's ok and even useful to have loop macros like FOR(i,n) (less code to type, and more importantly less chance of making a bug when in a hurry). Nothing against Java, there are a few top programmers who use Java too. :-)

  • Finally, although many of these top programmers may have C++/Java/Pascal as their "first language", they are not good because of their language, so you don't have to despair about that. Many of these same programmers have won contests like the ICFP contest even with intentionally using crazy languages like shell scripts, m4 (used in autoconf), and assembly (the team named "You Can't Spell Awesome Without ASM").

2 of 11
14

I liked Jerry Coffin's idea of plotting contestants of the Google AI contest, so I took all of the results and plotted them (calculated mean, standard deviation, and then graphed the normal distribution curves in Excel).

With Lua and JS, got this:

Without (there were few contestants, so maybe the results are skewed):

It looks like Java participants did markedly worse than the rest, while Go, Common Lisp, and C are on the better end.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ python or c++ for competitive programming?
r/learnprogramming on Reddit: Python or C++ for competitive programming?
November 27, 2022 -

I have been getting into programming and and have learnt JS and Ruby to a decent level, and Iโ€™ve dabbled in C.

I have been invited to a programming competition which mainly focuses on the number of problems which can be solved in a given time.

I have done a bit of research into competitive programming and I found that C++ is the most used language for its compiling speed. However in this competition they donโ€™t care about the time it takes to run, and with C++ would I take longer to write a program than Python, since the syntax is more complicated?

I have a while to the competition so we donโ€™t need to account for learning times

๐ŸŒ
GUVI
guvi.in โ€บ blog โ€บ programming languages โ€บ 5 best languages for competitive programming
5 Best Languages for Competitive Programming
January 9, 2026 - Python comes in as the best programming languages for Competitive Programming as it cuts short the time spent writing a code as compared to other conventional languages like Java, C, and C++.
๐ŸŒ
YouTube
youtube.com โ€บ shorts โ€บ DgH4xuzdofw
Best language for Competitive Programming | C++ Java Python | #shorts - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published ย  March 9, 2023
Top answer
1 of 10
14

In my experience, when people have excess difficulty coding algorithms in C, it's often because they are tightly coupling their data structure management with their algorithm instead of creating appropriate abstractions. For example, manually manipulating linked list pointers everywhere instead of making push() and pop() functions. They are too accustomed to having those abstractions provided to them.

While this problem is much more evident with lower level abstractions, failure to recognize tight coupling and create appropriate abstractions is a problem at any level. Practicing these skills in C until you can make an algorithm that looks clean and readable will carry over to any language you use.

The other problem I occasionally see among python programmers is difficulty adapting for performance at scale. Granted, performance isn't usually the primary concern, but the most pythonic way to implement an algorithm for a relatively small data structure can grind your system to a halt when you're working with gigabytes or more of data. Becoming a good C programmer helps you be more aware of those kinds of issues in any language.

Can you learn those skills in other languages? Sure, but C helps by making it a lot more obvious when you get it wrong.

That being said, I use python for algorithmic programming when I have a choice, even though I'm just as comfortable in C. Python has language features that make it very nice for that kind of programming, and performance differences are usually negligible. I can't speak to why other programmers who know both would choose C. I imagine a lot of them do it simply to set themselves apart from the crowd.

2 of 10
10

Researchers whose primary interest is not programming prefer higher level languages such as Python, because they can code a solution more readily in such languages than, say, C. Python is particularly well suited to this because it is more "prototyping" oriented, it is "batteries included," and it integrates with numerical libraries such as NumPy and SciPy.

If a researcher needs better performance, they will typically hand over the algorithm they created in Python to a Software Engineer, who will find ways to optimize it (up to, and including, recoding in C).