In Code Melange (Rated) contest problem, Xorangements giving WA to my solution asked 05 Apr '18, 14:13

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

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
