You are not logged in. Please login at to post your questions!



can anyone check the logic and say where am i going wrong???? ================here is my code=================== thanx in advance!!! :)

asked 22 Dec '18, 00:32

sabios's gravatar image

accept rate: 0%

Why are you using the value of an uninitialised variable n in Line 9 (memset)?

Edit -> Whoops! Found the bug!

From what I understood from going through your code, you are first checking what the remainder is upon division by 4.

Now, if the remainder is 0, we can solve the entire question in chunks of 4.

If the remainder is 1, we can the question in chunks of 4 and the last one in chunks of 5. (But we have to be careful not to use up the last chunk of 4 or else we'll be left with a single element). I see that you handled that case well.

And so on, just preserving the last 5 or 6 or 7 elements.

Now, the problem arises when the remainder is 0. Since the last block of 4 is never used in the while loop (as it could lead to the isolation of 1 or 2 or 3 elements), therefore in the case of remainder 0 too, the last block of 4 is not used. So we need to fill the last block manually again. (Or you can just relax the conditions of the while loop when j==0.)

Here's the link to your code which passes all the test cases!


answered 22 Dec '18, 00:59

masood786's gravatar image

accept rate: 13%

edited 22 Dec '18, 01:33

yeah bro..jst figured it out.............anyways thanx for such a quick reply....keep up the good work!!!!

(22 Dec '18, 11:33) sabios2★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 22 Dec '18, 00:32

question was seen: 279 times

last updated: 22 Dec '18, 11:33