×

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

 0 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 asked 05 Apr '18, 14:13 533●1●12 accept rate: 3%

 0 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 2.3k●1●5●16 accept rate: 10%
 0 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 https://www.codechef.com/viewsolution/21762084 answered 07 Dec '18, 05:36 4★david_s 101●1 accept rate: 12%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×2,559
×1,056
×105
×25

question asked: 05 Apr '18, 14:13

question was seen: 277 times

last updated: 07 Dec '18, 05:36