Recently, some people have asked for advice, so I decided to write a blog.
In this blog, I will talk about my approach to problem-solving, what I think about solving problems, how do I learn techniques, data structures and/or algorithms and others.
Solving is guessing
From my interpretation, solving any problem is just some sort of guessing: making an educated guess of the solution, validating, and repeating until solved. You can speed up the "guessing procedure" by simplifiying the problem to a certain degree by, for example, not considering obviously wrong solutions.
Abstraction and Decomposition
Usually, as soon as I finish reading a problem, I try to simplify it as much as possible. For example, sorting arrays, removing elements, handling simple cases, doing greedy decisions whenever can be done, rearranging formulas to more familiar ones, or decomposing the problems into several independent problems. You might even have to solve a harder problem, just because the harder version has a known solution, or you might reformulate the problem into a completely different one.
Visualisation
In my opinion, visualisation is very helpful when thinking about problems or learning new concepts. It makes it a lot easier to understand some seemingly advanced data structures, or to come up with solutions to problems. For example, you can think of arrays as histograms, think of numbers as a product of prime numbers, if it's a problem related to number theory, or as a binary representation, if the problem is about bitmasks, and so on. These interpretations make it easier to think about the problem.
Ego & Motivation
It is very easy to give up competitive programming, as it might seem difficult to improve, or gain rating in codeforces. When I do competitions, olympiads and contests, I usually enter with the "I have to be first" mindset. That usually keeps my brain busy with trying to solve the problems, and sometimes I even end up solving problems which I thought to be impossible at first. But be aware, this could also put you in a stressful situation, e.g. if you get stuck on some problem with "WA on test 2" verdicts, or ending up as the 10,000th place in a contest. Don't take losses like these too personal, look at them as an opportunity to grow (or just being unlucky): "well, seems like there's a case I haven't considered", "hmm, 10k people know how to solve problem X, so it shouldn't be too hard to learn". Encourage yourself that you can be the best.
Some practical advice
- Don't get stuck thinking about the same idea. Either continue, or change your strategy. Don't be afraid to think about new things.
- Don't force techniques/topics. "is this dp? is this greedy? is this fft?" is usually not a good strategy if your goal is to improve your pattern recognition or improve in general.
- If the problem seems too complex, think about a simpler version of the problem, special cases, e.g. $$$n=1$$$, $$$n=2$$$, $$$k=n$$$, $$$a_i \le 2$$$, the graph is a star, or whatever. You will get an outline of the solution for the general problem.
- Practice. "The simplest solution is usually the right one". Solving lots of problems gives a general understanding on how problems of some kind are solved. It also helps you improve implementation skills, as well as intuition.
P.S. I would like you to share the way you approach problem-solving and/or how you learn new techniques/dsa, so that I get a second opinion. Thanks :P








A really huge tip that helped me reach finals of national OI is to simply use pen and paper. While it sounds insignificant, holding several (sometimes up to 15) invariants/concepts/variables/definitions/... in your head makes it practically impossible to solve a problem. Pen and paper (Even better, an infinite canvas such as microsoft onenote) make you able to look at either structural or answer patterns. You will see immense improvements in using a canvas.
Another tip is to get the f**k out of your comfort zone. If you're good at greedy but bad at DP, practice DP to the point that it becomes automatic. This does not mean do not practice things you're good at.
Last but not least, one of my international olympiad medalist friends said this "It's never going to look good, and if it does, it's likely[actually] not. All you can do to improve is solve, solve, and solve."
I would like to add I can't hold 5 single-letter variables in my brain, that's why I make longer variable names.
can agree, pen and paper is actually so useful, the amount of approaches that you can go through, and at the same time keep a track of is just so useful when you are tackling a problem, I just love it!
The most human question I've ever heard for a long time
Thanks for the advice and idea. I am just curious to know did you have any sort of olympiad background or similar things Can we also add training math and other similar things, like USAMO, targeted problem solving practice to improve the raw thing ? so that the main part of breaking things down get's a bit easier
Well, yeah. Previously I did math olympiads and competitions, including AMC, SEAMO and IMC. I can't say I was very great at math, but yeah, I'd say my olympiad backround helped me with the "breaking things down" when it comes to cp problems. I don't think you have to be solving math problems tho, codeforces problems are just as good, but doesn't hurt to try.
okay I guess, I might as well try the thing, math problems get me off guard in contests that's why I thought of this
orz Timosh
You didn’t mention anything about how you learn new topics, such as data structures, algorithms, or other unfamiliar concepts.
I guess, yeah. Learning new topics, data structures, algorithms happens as you solve problems. I can learn just by solving problems, just a little bit of thinking on a good problem, and boom, I've learnt something. Sometimes it's a little harder, e.g. can you really come up with algorithms like MST, Kadane's and etc.? I juse learn these from cp-algorithms.com.
can you tell how often do you practice like do you solve random problems or rating wise or do virtual contests
I mostly do contests only. If I'm very bored, I could do duels or gitguds on Errichto/GF server. Yes, I solve problems randomly, and usually it's in the 2000-2400 range. I do virtual contests for OI-style only, I'm not motivated enough to do vc on CF contests :<
How do you handle burnout? Do you take a complete break from CP for a while?
I think it is better to set one small task for yourself per day. F.e. one past OI problem, a harder question from recent contests, or maybe just read about a topic from usaco.guide or some other website. If you accomplish your small task maybe you can get motivated to do something else related to CP and go from there.
Well, I can't really say that I practise, so that there's a room for a burnout. I always do contests tho: don't really like to miss a chance to perform. But if you are about to lock in, and afraid of giving up sometime, do easier problems per week. This way, your brain will be like "oh, this is so ez, gimme something harder".
What do you think about competitive programing is more like patter-identification?
Like chess, but the topic here vary a lot and can be combine to make a problem using a los of patter coming from other problems.
Not sure at all, guessing is problably coming from not knowing "all enough patterns", or how to break a problem to be able to found new ways... this last part is be able to make patterns. Idk, is a fast though
if by "knowing all patterns" you mean knowing the solution to all the problems, well, you don't need to guess anything, obviously. I think guessing is required, as there is not a single general way to solve any problem: you don't know what techniques, theorems, algorithms work, before you try them. I would make an analogy, and say that solving a problem is like a maze. You could just be lucky and go straight to the exit, or end up going to all the dead ends. By solving more and more problems, you will start realising what ways lead to a dead end, without going there, which I think is where pattern recognition helps.
i get the maze thing, and problably is likely to be try (throw a bunch of ideas to see what can works in a problem)
My analogy is with chess, since there is no way you will encounter with the same position as one you study before (don't count openings). But still we take our time to analize some posicion, attack patterns, posicional patterns, strategy patterns, and other stuff.
With problem solving, there is a kit tool for some basic, example as binary search, prefix sum, segment tree, DFS, and other depending of the topic (math, graph, query, even some combination of topics). There is other less common like those ad-hoc/implementation. (I don't know what to recomend besides of practice and some sence of math-proff [don't deny i solve them with "intuition" sometimes... {i'm weak x_X}])
So yeah, there is a need to increase your tool kit of patterns (algoritm, math stuff, data structure...). While also working in improving either the patter recognition/guessing? or how to be able solve out of the scope things (how you solve a problem who is nothing you see before?)
Btw, i still need to think how to improve this part in this, here are some mine thougsh
thank you Timosh on that...... Good boooy
I think the best way to improve your intuition, and therefore problem solving ability, is to stop solving topic wise; just disable topic tags all together. You will naturally discover any technique you actually need after solving enough problems at your rating and will more efficiently learn how to spot them in the wild. It's what I started doing a bit ago when solving the CP-31 sheet and I have felt noticeable improvement. I can really only attest to this for lower rated competitors tho.
the legend.
Ngl, that's some seriously great advice.
Thanks for such genuine advice.