GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 3 July 2022

[Solution] Xor Permutation CodeChef Solution


Chef has received a challenge for which he needs your help.

Given N, find a permutation P of numbers (1,2,,N) such that:

  • PiPi+1Pi+2 , where (1iN2). Here  denotes the bitwise XOR operation.

If multiple such permutations exist, print any. If no such permutation exists, print 1.

Note that, a permutation of length N is a sequence of N integers P=(P1,P2,,PN) such that every integer from 1 to N (inclusive) appears in it exactly once. For example, (2,5,4,1,3) is a permutation of length 5 while (2,5,2,1,3) is not.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.
  • Each test case contains of a single integer as input, N - the length of the required permutation.

Output Format

For each test case, output in a new line, N space-separated integers, denoting a permutation satisfying the condition.
If multiple such permutations exist, print any. If no such permutation exists, print 1.

Constraints

  • 1T500
  • 3N105
  • Sum of N over all test cases does not exceed 

No comments:

Post a Comment