7 things C++ coding on TopCoder taught me
I have recently discovered the field of competitive programming.My first venture was a set of TopCoder problems .There were three problems in total:While the first two were relatively simple,the last one was a huge rock.When I found the solution though it was so elegant and graceful ,I fell in love with it.In this post,I share with you my experiences and takeaways.
1. The Traditional way- Pen & Paper
Working out the logic with paper/pen helps me figure out the code for corner cases mentioned in test case as well.This way the time you spend iterating over logical errors is much less.
2. Oh,the mighty compiler!
After working out the algorithm and bringing it to the editor , you might come across major issues which you might not have even thought of.But you’ll thank the compiler for being there in your life.
3. Practice makes a man perfect or so I hope.
It’s not easy to solve a problem within the time constraints ,but at the end of it ,I always feel joy in solving a problem.There is no way you can ace a competitive programming challenge unless you have lots and lots of practice.
4. At the end of the day , you’ll be a confident problem solver
The most important realization I had during competitive programming :If we break down a seemingly tough problem into simpler sub-problems ,we can find a solution to it .When I started programming ,I always had this fear in me, I didn’t know how to approach the problem,where to start tinkering,it was always overwhelming.Gradually I developed an intuition to attack problems.I can solve most problems now ; getting it to work on the optimum complexity is the tricky part now.But I am not complaining.
5. Persistence is the key
You will need drive and resilience to not give up .Every time you submit a solution and you get either a “Wrong Answer” or “Time Out” error ,it’s going to be frustrating.The real challenge is being gritty and keep submitting alternate solutions till you get it right.
6. You need to keep a good memory,my friend!
A C/C++ programmer who has a bad memory really has odds stacked against him . You either know how to do all the string manipulations or you don’t:If you don’t or plain forgot(for you didn’t use it for a long time), finding out how to do those simple things will usurp a lot of your time.Let’s not even start on the BigIntegers issue,Python makes it look silly with it’s BigNum integer type and C++ makes them look exotic ;)
7. There are some trivial side-effects too!
After figuring out everything , even if the code works , you can’t bring these coding skills to your work. For all you know atoi or sprintf might be a big no no for production code.
Here is a beginner’s guide for anyone intrigued to try out CP :
And a course by Stanford around Competitive Programming Contests:
Please add your insights in the field of Competitive Programming in the comments section.
What are your takeaways ? What inspires you to participate in coding challenges? What’s the feeling you get after solving a problem?
What’s your story?