Arshiya is just three and she already started programming. She has learned how to write loops. Recen…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
Ok…it is a range from 1 to n inclusive and at least half of them will be odd and half of them will be even! now if the range is odd i.e. my res variable is odd then odd number will be more unless exactly half of the number will be odd.
I hope you are not regarding my theory as a trash .
Try out your theory on paper and see if it works. Take some numbers and manually calculate the summation of their odd ones. Now try to do the same thing using your method. Check if these matches.
The problem is not in your theory but how you are implementing it. In an inclusive range if you deduct the lower value fron the upper value sometimes you might lose the lower value itself! Let me give you an example. Assume that you want to know the number of number in the range 2 to 4 inclusive. Now there are 3 numbers which are 2, 3 and 4. However, if you do 4 - 2 then the answer would be 2! Meaning that you are losing a number in your calculation!
You have done the same thing here. Check if you have lost any number in your calculation.
Try a couple of more times cause I think i have given you all the clues you need. It got half the test cases right cause your code will generate AC for half of the cases. Try to fix the rest yourself.