This happens very often that i solve a question try it for sometime(about an hour or two) but couldnt solve it. So should i see the solutions already available? Also sometimes i get wrong answer but i could not find what is wrong in my solution. Seeing solution is it fair?
if you understand the problem, and feel yourself confident enough to solve the problem on your own, then you should go for it and dont see the solution. And, if you understand the problem but not the logic to solve it, then think of the best nave solution possible, and to fully solve it and learn logics you may see the solution which you understand better. You will realise optimisation level from your own answer.
Seeing the solution depends on you. But I strongly suggest not to look at a solution until you are left with no hope. If you try hard enough, you are bound to come up with something ( and in the process, you will learn new things as well ).
If your code shows no error, but gets Wrong Answer, that means there are some cases which you are missing. Now that’s where the important part is. You must be able to make some test cases of your own ( you will have to do that the good old fashion way by solving the test case with pen and paper ). Try to make many test cases, and try your code for that, if your code doesn’t give the right output, you now know which test case it is failing. Then, you try to fix that. ( most often, the correct output’s can be easily achieved using a certain formula, or the answers of relatively close test cases, may follow a pattern. For example, for input 1,2,3,4 , etc, the output may follow a certain pattern )
Now by doing this, there is no harm for you. You will keep learning more things and keep getting better at programming the more you try. You will also get better at making your own test cases. A lot of people are lazy and don’t make too many test cases, and when they get Wrong Answer, they immediately post the code on the codechef Forum asking why they are getting that. But, it’s always best to try make some yourself. If you try a lot, and test for many cases, but still getting WA, then you can ask here for help.
I suggest that you look at other solutions after you solve the problem, and then you will know how others did it. Something more to learn. Some new ways on doing it. Then try implementing that code as well. Always good to try more stuff.
But above all, when you are able to solve a problem by yourself, there is a sort of special Happiness that you get, after lots of hard work, you were able to solve it by yourself. Now that is a feeling that will get you motivated and you will be eager to try more problems. That feeling you get, will be much better than the one you get after looking at another solution and implementing that.
So I would advise not to look at the solutions unless you are at the verge of going MAD because of being unable to solve it. But then also, don’t just copy paste the code. Learn the logic, and make your own code. In that way, you will at least get some more experience in coding.
Happy Coding…
I would suggest that there is no need to spend hour or two on tasks, especially when you are newbie; it is wasting of time, and you better learn something new in that time, instead of trying to reinvent some part of it by yourself.