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
๐ŸŒ
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 โ€บ java โ€บ c-vs-java-vs-python
C vs C++ vs Java vs Python vs JavaScript - GeeksforGeeks
Extends C with classes, templates and RAII. Used in game engines, simulations and high-performance applications. Java โ€“ Compiled to bytecode, runs on JVM (interpreted/JIT-compiled). Platform-independent, strongly typed, with automatic garbage collection. Popular for enterprise android and backend systems. Python โ€“ Dynamically typed, typically first compiled and then interpreted via bytecode execution.
Published ย  August 12, 2025
Discussions

What's better for competitive programming, is it Java, Python, or JavaScript?
Iโ€™d do Java. I use python mainly and I love it, but there are some downsides to it. One positive thing about it is that everything is like 10x easier to implement and those 1 liners are sweet lol. So much builtin power & libraries. However, I think in the process of doing leetcode & preparation, Java would be more beneficial to understanding of data structures & OOP. Java is a pretty popular language as well, and having a good understanding of it, I think would more readily translate down to javascript later down the line than I think python would. More on reddit.com
๐ŸŒ r/learnprogramming
2
1
September 18, 2021
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
language agnostic - Why do programming competition contestants use C++ and Java? - Stack Overflow
After competing in and following ... contestants that used C/C++ 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 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What are your views on C++ vs Python (vs Java also if you use it) for LeetCode and competitive programming?
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. More on reddit.com
๐ŸŒ r/leetcode
4
9
September 19, 2022
๐ŸŒ
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.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Best Programming Language For Competitive Programming | C++ vs Java vs Python | GeeksforGeeks - YouTube
Thereโ€™s a very common question that often comes to the mind of individuals before getting into the Competitive Programming world - Which is the best programm...
Published ย  July 3, 2021
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ c-vs-c-vs-java-vs-python-vs-php
C vs C++ vs Java vs Python vs PHP - GeeksforGeeks
August 13, 2025 - Extends C with classes, templates, and RAII. Used in game engines, simulations, and high-performance applications. Java: Compiled to bytecode, runs on JVM (interpreted/JIT-compiled). Platform-independent, strongly typed, with automatic garbage collection. Popular for enterprise, Android, and backend systems. Python: Dynamically typed, typically first compiled and then interpreted via bytecode execution.
๐ŸŒ
Quora
codingcontest.quora.com โ€บ Do-you-advise-languages-like-Python-or-Java-for-competitive-coding-rather-than-C-C
Do you advise languages like Python or Java for competitive coding rather than C/C++? - Competitive Programming for Beginners - Quora
Answer: I would say go Java, if not want to go for C++. Yes Java is a bit slow than C++, but not very much as Python. Java is still good at almost all of the competitive programming problems with vast amounts of library and rich Apis.
Find elsewhere
๐ŸŒ
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
So the simple answer is pick either Java or C++ (C++ or even C have been around for a long time and show no signs of going anywhere soon), and also Python, afterwards. ... Oh dearโ€ฆ I hope you know what is competitive programming.
๐ŸŒ
Quora
quora.com โ€บ Among-Java-C-and-Python-which-is-the-best-language-for-competitive-programming
Among Java, C++ and Python, which is the best language for competitive programming? - Quora
Answer (1 of 10): Each language has its own merits and demerits, So ultimately no language is best nor any is worst. Java Pros: In context of Competitive programming, Collections framework will provide you many option for using an apt Data structure, extensive libraries are also a big plus in...
๐ŸŒ
Medium
medium.com โ€บ @burninghell โ€บ cpp-vs-java-vs-python-258c087eff2d
CPP vs Java vs Python. Which one to choose? | by burninghell | Medium
October 4, 2021 - So >99% of the problems you face would already have been solved, you just need to understand the solution rather than doing research work and brainstorming. In addition to this, C++ is much faster than Java and Python...
๐ŸŒ
Quora
quora.com โ€บ C-vs-Java-vs-Python-who-will-win-64
C++ vs Java vs Python: who will win? - Quora
Python is trending these days,the ... and Java Developers.For Competitive Coding,U write 20 lines for Java/C++ to achieve a result and same can be done in 2โ€“3 lines using Python.The language teaches u to write 1 liners ...
๐ŸŒ
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++.
๐ŸŒ
Quora
quora.com โ€บ What-are-the-reasons-for-C-being-preferred-over-Java-in-competitive-programming
What are the reasons for C++ being preferred over Java in competitive programming? - Quora
One of the reasons we do competitive programming is to learn computer science fundamentals. The more you know what happens underneath the metal, the better the code you write. C++ strikes the right balance between programming abstractions(like objects, templates, classes etc.) and implementation details(pointers, null checking, pass by reference etc.). You can shift gears when you want to. Java and Python hide all the details for you so that you donโ€™t worry about memory management, the size of your data structure(this is critical in some problems).
๐ŸŒ
Codeforces
codeforces.com โ€บ blog โ€บ entry โ€บ 46506
Python vs Java in Competitive Programming - Codeforces
I solved the same problem in two different programming languages: Java and Python. The Java program is usually longer in terms of LOCs, it uses more memory and his time execution is slower than Python code. As we can see in the next screenshot:
๐ŸŒ
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 ...
๐ŸŒ
Lasting Dynamics
lastingdynamics.com โ€บ home โ€บ build a software โ€บ python vs java, c++ & more: ultimate showdown in 2025-2026
Python VS Java, C++ & More: Ultimate Showdown in 2025-2026
1 month ago - C offers raw performance and control, making it ideal for systems programming and applications where every millisecond counts. Python prioritizes readability and developer productivity, allowing teams to move faster at the cost of execution speed.
๐ŸŒ
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 ...
๐ŸŒ
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.
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.