Hi.
This might seem like a silly question, but here’s the thing.
For solving these problems, we are given a very specific entry. It has its own format, and there is a small amount of possible errors in given input.
I usually make very minimal checks when parsing the incoming data and write extremely unsafe code to sort it out without making a -in this specific problem-solving instance- somewhat unnecessary number of verifications.
Say, if the input data is an int with specific constraints, I don’t check to make sure it verifies these constraints, unless I specifically need to when solving the problem. If it’s a ‘xxxx;xxxx’ format, I don’t check to make sure that there is only one semi-colon, I write dirty code to parse it and give me xxxx and xxxx without too much hassle.
Since I’m also still in the ‘easy’ section, I tend to write mostly unoptimised code and don’t look out for the best data structures. So far, anyway. I’m fairly sure that once I start hitting the harder problems I’ll need to find more efficient data structures, find faster algorithms, etc.
I do tend to make notes of where and when my code is unsafe or much slower than it could be, but overall, would you agree with my approach or would you say that I should write a proper parser everytime and optimise my code to the point of overkill for every problem ?