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


In Code Melange (Rated) contest problem, Xorangements problem giving WA to my solution

In Code Melange (Rated) contest problem, Xorangements giving WA to my solution
According to me, my Code is passing all test cases.. can anyOne give any test case in which my program is getting failed
and if anyOne come to know why my program getting failed, that reason will be bonus..
thanks in Advance

Problem link In practice section
MySolution LInk

asked 05 Apr '18, 14:13

hemant_dhanuka's gravatar image

accept rate: 3%

For test case 1 11 . Your code gives -1. But correct answer is 3 2 6 7 5 4 0 1 9 8 10.And other combinations.

P.S. - I'm still waiting for the editorials.


answered 19 Apr '18, 08:13

aryanc403's gravatar image

accept rate: 10%

I have devised a neat, fast method of solution, which requires no clever algorithms or data structures, not even an array.

Start with the largest number to be printed = N - 1.

Identify the index of the last binary 1, counting from 0 at the right.

Loop until no more 1s of the original number are left:

Change the identified 1 to a 0.

If this is the last digit (index 0), write the number.

Else work down recursively, starting one index down - at each index, if reached the last digit write the number, swap the last digit 0 to 1 or 1 to 0, and write the number again. Else call recursively, with the index of the digit reduced by 1, swap the digit at the current index, and call recursively again with the index again reduced by 1.

Identify the index of the next last binary 1 in the original number, taking care not to disturb later digits which may have been changed during the recursive calls.

Example - given decimal 11, output 10 8 9 1 0 2 3 7 6 4 5 = binary 1010 1000 1001 1 0 10 11 111 110 100 101

My solution (in C) is at


answered 07 Dec '18, 05:36

david_s's gravatar image

accept rate: 12%

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: 05 Apr '18, 14:13

question was seen: 277 times

last updated: 07 Dec '18, 05:36