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
Is using Java as effective as using C++ in Competitive Programming?
The most useful language tool in competitive programming is a powerful standard library and toolkit filled with common data structures and algorithms. You don't want to be building a linked list from scratch every time. Java's built-in library is much more extensive than C++'s, and in that sense, it's much better for competitive programming. However, there's no reason a competitor can't use common C++ standard libraries to make up for that language shortcoming, which puts them on even footing again. Now, some competitive programming problems come down to a difference of seconds for problems with a lot of zeroes, and for raw mathematical calculation speed, C++ is usually better than Java, so that's a point for C++. On the other hand, debugging coding errors can frequently take longer in C++ than in in Java, but for the top competitive programmers, if you're spending time debugging, you've already lost, so that's less of a big deal. Similarly, for raw typing speed: Java's a bit more verbose than C++, which is a small speed cost. Really they're both fine. C++ is common. Java is seen sometimes. Personally I prefer Python. The most important thing is how proficient YOU are with that language, not how good the language could be in theory. More on reddit.com
๐ŸŒ r/learnprogramming
9
4
March 23, 2021
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.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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++.
๐ŸŒ
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:
๐ŸŒ
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).
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ is using java as effective as using c++ in competitive programming?
r/learnprogramming on Reddit: Is using Java as effective as using C++ in Competitive Programming?
March 23, 2021 -

I am learning Data Structures using Java. I already know some programming and want to improve my programming logic by starting with CP.

Can I do competitive programming in Java effectively? I have read that most CP programmers use C++.

Top answer
1 of 3
6
The most useful language tool in competitive programming is a powerful standard library and toolkit filled with common data structures and algorithms. You don't want to be building a linked list from scratch every time. Java's built-in library is much more extensive than C++'s, and in that sense, it's much better for competitive programming. However, there's no reason a competitor can't use common C++ standard libraries to make up for that language shortcoming, which puts them on even footing again. Now, some competitive programming problems come down to a difference of seconds for problems with a lot of zeroes, and for raw mathematical calculation speed, C++ is usually better than Java, so that's a point for C++. On the other hand, debugging coding errors can frequently take longer in C++ than in in Java, but for the top competitive programmers, if you're spending time debugging, you've already lost, so that's less of a big deal. Similarly, for raw typing speed: Java's a bit more verbose than C++, which is a small speed cost. Really they're both fine. C++ is common. Java is seen sometimes. Personally I prefer Python. The most important thing is how proficient YOU are with that language, not how good the language could be in theory.
2 of 3
2
C++ is slightly faster than java,few lines to type than java and c++ STL is lot better than java container classes. Sometimes same algorithm implemented by java shows time limit exceeded error in some competitive coding platforms where c++ is accepted.