Competitive Programming: What is the best way to progress through practice problems on CodeChef, SPOJ, TopCoder, etc.?
-
I've been solving problems consistently on CodeChef and even take part in their cook-offs and challenges. However, There one thing that bothers me. I solve problems and move forward without looking much into what was put into it. Since i get decent runtimes, i don't bother much to look at the editorials or the tutorials related to those problems. Even when I've tried, the solutions involve a quick formula or some really 'out-of-the-box' logic that i couldn't have come up with in a million years. This convinces me that the method I've used sort of presses on the fact that i have my on approach to solving problems and stick to what i'm doing and keep solving moving problems. And i AM able to, that's not the issue. However will this really help me in the long term? Should i keep a track of every little trick/innovative algorithm/solution i/problems setters come up for the problem? Whats the best way to keep a track of everything we learn through the problems? Or even should I? I'm preparing for the ACM-ICPC and am a first year CSE undergrad. Some tips in the context of the question above would really be useful. Thanks in advance
-
Answer:
I personally like Codeforces better than the other online judges. It has a lot of nice problems, there are online competitions almost every week, I prefer its interface better than the Topcoder arena, it's easier to search for problems and sort them by difficulty, and it supports more languages than Topcoder. There are probably other reasons why I prefer it, but this is what comes to my mind at the moment. As for what to read, the most widely recommended textbook is Introduction to Algorithms by CLRS. The Topcoder Algorithm tutorials are also a great resource. As for how to practice, then I think it's a good idea to just solve problems and whenever you can't figure out a problem, ask for hints, or check out its solution. If the solution relies on a concept that is foreign to you, then you can study that concept from a textbook or check out tutorials on it. I think this method is better than just spending most of your time studying from a textbook because reading can get boring sometimes, and also because this way you will get more exposure to ideas. A very useful thing to consider when solving problems is whether you were able to solve a problem or not, always check out its solution in the editorials on Topcoder/Codeforces, and check out the solutions of other people (CF and Topcoder allow you to view the solutions of others). If the solution was different from yours, make sure you understand it. That way you will pick up new ideas and tricks that you can apply in future problems. Also, If you weren't able to solve a problem, make sure to come back to it later and try to solve it without peeking at the solution. All that being said, I think a good place to start solving problems is by sorting the problems by difficulty and doing them in sequence. As for what language to use, this is up to you. But if you're looking forward to compete in the ACM ICPC, then you might want to stick to either Java or C/C++. If not, then you can use whatever language is supported by your online judge of choice. Just make sure that you are comfortable with your programming language of choice and get comfortable with its standard library. Using the functionality provided in the standard library whenever possible will save you a lot of coding time and will minimize the possibility of bugs in your code.
Mostafa Hany Gomaa at Quora Visit the source
Other answers
You should keep track of the problems you solve . This may not be applicable to all the problems . You may solve a few problems under 5 to 10 minutes , don't keep track of those problems as most of them will be easy to implement . Some problems will take hours or even days , keep track of such problems. Once you solve them , put them in git / create a new folder for them . It seems that you are confidant about your algorithm used for a particular problem . That's not bad , but having a look at the editorial is appreciable.
Shankar N
Thanks for A2A!I'm a beginner just like you, but as I've been A2Aed, I'll try to answer.Ok, Here you go...let's get it started... There are many OJs for practicing, the very first question that comes in my mind is which one to choose? So first I'll make a list of OJs and the what are the speciality of it! http://www.spoj.com - highly recommended by All competitive Programmers. Large number of Problems and of very good quality. Editorials and solutions are available online if you got stuck while solving problems. Supporting Website - 1 .http://spojtoolkit.com 2. http://problemclassifier.appspot.com http://uva.onlinejudge.org- You can try this for ICPC archives . And it's website http://uhunt.felix-halim.net is just Awesome. It is very helpful for Solving problems category wise. Supporting website - http://uvatoolkit.com/problemssolve.php. http://acm.timus.ru/problemset.aspx - Category wise problem Sets. But I never tried this. http://lightoj.com/index.php - Good one for Beginners! I'm going to select SPOJ, as seniors and Pro programmers have recommended it. Sort problems as per number of users solved, and start practicing. So solve at least 4-5 Problems daily on SPOJ. Even if you solve 4 problems(6-7 Hours ) daily in a month it will be 30*4 = 120 Problems. After solving 50 problems on SPOJ, you need Knowledge of Algorithms So get a book "Introduction to Algorithms" and read it, solve it. Read my answer - Never miss even a single contest!!! Download Coding Calendar App - https://play.google.com/store/apps/details?id=com.limitskyapps.CodingCalendar&hl=en Websites - 1. http://www.codechef.com 2. http://www.codeforces.com 3. http://www.topcoder.com 4. http://www.hackerrank.com 5. http://www.hackerearth.com - You can practice on these websites also. View Others solution, read it and learn tricks they use! After contests NEVER ignore editorials!!! You'll never progress if you are only participating in the contest. In 3rd month - Practice Problems topic wise. Learn what is DP? Why people do others say "This problem be solved using KMP Algorithm" ? What does Greedy mean? I mean you have to improve your Algorithmic knowledge..Ask this questions yourself while solving . 1. What will be running time of my solution? 2. Will it pass all the testcases? 3. Proof of your solution. 3. N is about 10^20 my code runs in O(n^2) time, will it work? Lastly Practice..Participate..read editorials...read others solution..Learn Tricks..again Practice...this is ONLY MANTRA! I want to mention few websites for you...and it shall guide you :D http://www.mathblog.dk/- For Project Euler solutions and best place to improve your mathematical skills. http://www.algorithmist.com/index.php/Main_Page http://wcipeg.com/wiki/Main_Page http://e-maxx.ru/algo/ - Use chrome My repository - http://vicky002.github.io/AlgoWiki/ - It contains all the websites, resources, articles, blogs, free pdfs, Algorithm implementations etc. You can also contribute to it! Fork it in your projects..I'll keep on adding there. Language - C/C++ or JAVA? :/ C - Implementing different algorithms will be a bit ticky and it will take time. You have to use pointers, and one segmentation fault may eat your 30 minutes. C is Very fast though. JAVA - Running time issues but it has Big Integer class :D. But problems in which we need to use Big-Integer class will be few. And if time limit is tight, it may so happen that you will always get TLE. C++ - Highly recommended! It is very fast. Implementing different algorithms algorithms in quite easy. C++ and STL is all you need. Big-Integer problems can be solved using structures creating your own Class and methods to tackle this problem. You will learn this when you read others solutions! so I think you should choose C++!! Hope it helps!! Keep Coding thank you for A2A! Thank you :)
Vikesh Tiwari
Well this is the same ideology that I had some time back. When I used to solve problems in long challenges organized by http://codechef.com , I never really cared to check out the editorial for any problem that I was successfully able to solve. However most of the blogs that I have read and even some answers here on Quora too, they all focus on the fact that reading the editorials and other's solution does in fact help. This is true and I realized this after actually trying this myself. Most of the times, in fact 90% of the times, I don't get 0.0 time whenever my solution gets accepted. However, there are solutions out there including the ones proposed by the problem tester and setter that get accepted in 0.0. That is really cool. One thing that is clear is that just getting a green tick for your problem is not Enough.. Trust me, reading other's solutions and the editorials actually helps to enhance your knowledge greatly. Sometimes its just some tips and tricks and other sort of optimizations employed by some coders whereas in some cases they might have used a completely different data structure to their advantage that we might not even think. No doubt that your logic is also important because that is your thinking but at the end of the day, reading editorials and glancing through other's solutions is always helpful for your knowledge. Now as for your question. How do you actually keep track of all these things you learn. Personally, making notes always works for me. Whatever new trick or data structure or algorithm I read, I jot it down in a notebook for future reference. I keep revising and after 2-3 iterations, just 5 minutes should do it and all your concepts will be renewed. Frankly speaking, most of the times those same set of tricks and hacks come out to be very useful in some future problems and that is the point my friend where you realize that the editorial you read actually helped you. Hope this helps !!! Happy coding !!
Sachin Malhotra
Something that I've recently discovered is the importance of letting yourself struggle, seriously. Think of a hard CodeForces problem like a tough physical workout that you may not be able to complete. The moments when your muscles burn, and you continue to keep going, could almost be similarly viewed as the moments when you are knees deep in a tough problem and don't know where to go, or don't know what further optimization to make. Sure, you can practice so much that you learn nearly every trick in the book, but I think learning how to progress through the "struggle stage" is invaluable. You're essentially teaching yourself how to quickly and effectively dig yourself out of a hole. If the first analogy didn't help you understand, think of the quote "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime." Think of the fish as the "clever trick" to solving some problem. Let yourself struggle until you've reached some point where you don't feel there would be any further benefit for you to continue. Doing this will almost certainly increase your ability to not only solve more problems, but also to come up with these clever tricks yourself and think outside of the box in the heat of the moment instead of feeling completely lost.
Cameron Reynoldson
Well, you packed a lot into this question. The simple answer is that practice makes perfect (and, in many ways, no one will ever be a perfect coder). Coding languages are like foreign languages in the sense that you have to practice them regularly to remain proficient. Even if the practice isn't always Mensa-level it is enough to prevent getting rusty. In my opinion and from what I've heard, http://HackerRank.com is a great site to practice your coding because it offers variety of: domains, languages, and difficulty. It's also got a fun, competitive community where you can earn badges and compete in hackathons (maybe even win prizes while doing so).
Tom Nikl
There are several things you can do that I would advise were good practice (and good for exposure): --join a site that offers programming puzzles and ranks you based on puzzles solved, and preferably one that also times you (or time yourself). This will expose you to both practical experience problem solving and allow you to build a searchable profile. Many sites that do this sort of thing also offer profiles or rankings to employers, or can be referenced with your ranking. This will also offer you opportunities to compete with other programmers, since such sites often host competitions. Sites like HackerRank, TopCoder, etc are examples of this. --participate in code jams, capture the flag competitions, or yearly coding competitions. Even if you place poorly, you'll still get valuable experience from participating. --join a project on any of the collaborative programming sites that looks like it's within your skills and able to be finished. Sites like GitHub or any other open source project site are places to get this kind of experience. --answer questions on programming that are within your skill sets on sites that have dedicated resources for programming or that have sections for programming. Questions here, on StackExchange, or anywhere that coding questions are posted are a great opportunity to show off your knowledge and be a part of building a reputation. --create a blog or other personal site where you write posts including code samples that solve common problems, creating resources for others and showcasing your own abilities. This also allows you to give a link to employers to a site which demonstrates your specific abilities, versus your collaborative abilities or your ranking on various competitive sites. --read and practice. This is, of course, philosophical and/or general, but absolutely necessary. Embrace several languages, and research the demand for those languages so that your language stable is current and in high demand (for instance, The sites you join are up to you, but I'd advise joining the following due to the size of their audiences, reputation, offering cash prizes, the kinds of puzzles they pose, and/or their relationship to employers: TopCoder HackerRank Project Euler (they require you to implement specific algorithms) Stack Exchange (for resources) GitHub/SourceForge As far as preparing, several of those suggestions allow preparation. Solving puzzles on HackerRank or TopCoder before you compete is preparation, as is the task of writing blog entries that include partial solutions to common problems and participating in open source projects. The puzzles on those sites start very simple, and can be tackled on your own time, providing you with opportunities to learn how to handle new situations (and prompting you to learn new things in order to tackle those problems.) And, of course, reading is fundamental to growth. I have several books at home on algorithms, and peruse the blogs or answers of various people with more experience than I do in order to learn new algorithms. If I were you, I'd couple this with math--specifically, I would make myself draft programs to calculate various things for the practice implementing the math side of programming. Since programs work based on their logic, and computing is heavily based on various sorts of math, this will give you increased understanding and insight into the back end of your computer. An example here would be writing something that calculates derivatives of various types, or that calculates the first X entries in a series. It's one thing to know the math and another to be able to make a computer do it from scratch, and being able to get a computer to do this from scratch is a sign of skill. Several of the puzzle sites will also ask you to implement algorithms (Project Euler, in particular, asks you to implement specific algorithms), which is another way to get exposure to new algorithms and practice implementing the ones you know. As far as specific books, whatever works for you is fine--as you no doubt know, you'll be reading books, sites that answer coding questions, API, and anything else you can get your hands on. There's a fair number of books on algorithms out there. If you can, add to any easier to read and understand books on algorithms reading Donald Knuth's seminal volumes on coding--even if it's heavy reading, his work is excellent at discussing algorithms and the math from which they spring. You'd be hard-pressed to beat him as a source of knowledge on how to get computers to do things and a bit about why they do from the math side. You don't have to take it from the math side if you don't want to, of course, but if you're at all interested in why things behave the way they do and what makes algorithms behave in particular ways (as well as exposure to tons of algorithms), The Art of Computer Programming is a great place to go.
Carrie Cutler
Many excellent answers has already been posted but I will answer this question as I have been A2A, but in a different context. People have answered what you should do, here's what you shouldn't do, the mistakes I made in my first 6 months:1.) Lack of knowledge about the websites.It's important to know which website has what type of questions. You know yourself better than anyone, you know what you're lacking and therefore you should choose website accordingly. For example, if you lacking in dp then you should choose SPOJ and do dp specific problems. Hackerrank won't be good for that and if you start solving dp problems on hackerrank you won't have as good exposure and improvement as compared to SPOJ. While Hackerrank is better for getting introduced to new algorithm because of its partial scoring model. 2.) Practice.Practice a lot and never be content with yourself. They say "be satisfied with where you are", it's not like that while acquiring a skill. Never be satisfied. I always get this feeling that I used to practice less than what I do now and I am sure I will feel the same way 6 months from now when I look back at this present month.3.) Circulate between websites.I practiced only on Hackerrank in the start. I didn't knew other websites such as TopCoder, Codeforces and SPOJ even existed. Despite all being competitive programming websites questions on these websites differ, especially on TopCoder. Do not practice only on one website, after solving a significant amount of questions on one move onto other. This will help you familiarize with different types of questions.4.)Upsolve.I can't stress this enough, always upsolve questions after the contest. I didn't gave much attention to the problems I was not able to solve during contest and therefore I didn't knew about algorithms and techniques to be used to solve that problem. Upsolving is important for improvement, do it.5.) Participate regularly.As I said I didn't even knew TC and CF existed, my contest participation was on mostly on HR and sometimes on Codechef. Apart from your regular trainings participate in contests on all websites as well. The more you take part in contests the more you will learn and improve.Now your questions,Topcoder has participants mostly from European countries. Despite the UX of the applet being problem for some, the questions are good and that makes it worth competing. Though configuring it with plugins makes it as easier as other websites. SPOJ is not a contest site, it does not hold contests. It's a repository of questions which have been added through the years. Some of these questions are from on-site contests(like ACM etc). Codechef is an Indian website and most of the participants are from India. It holds regular contests, college contests and mirrors of ACM-ICPC regionals contests.Just start with hackerrank's "30 days of code" like contests as those are tailored for newbie. Use textbooks only as reference, use editorials and some red-coder's code to learn(find some good coder whose code is easy to read and use that guy's code to learn). Use whichever language you like. ACM only allows C/C++ & java. C++ is the fastest and has STL so I recommend C++.Thanks for the A2A!
Shubham Singh
1-2 months: practice on SPOJ(from easy to hard ,follow this link: http://spoj.com/problems/classical/sort=-6)- solve atleast 300 problem (for this period don't try any other site).(You'll learn new technique in each problem). afterwards: participate in codechef long contest,topcoder SRM, codeforces contest,Hackerrank contest follow their editorials for unsolved problems. remember: don't jump to multiple sites for problems in your practice period,they'll do mess.
Ravi Verma
This is superbly answered in the following answer :
Arjun M Das
Related Q & A:
- What is the best way to distribute an audio/video feed from a computer to TVs over existing indoor coax cable?Best solution by Audio-Video Production
- What is the best way to clean LEGO bricks?Best solution by bricks.stackexchange.com
- What is the best way to make UI for an Isometric game in Java?Best solution by Game Development
- What is the best way to calculate a date difference?Best solution by Stack Overflow
- What is the best way to count lines in file?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.