1339. Find XOR of All Permutations

MediumBit ManipulationBit ManipulationXORPermutations

Given a non-negative integer n, form every distinct permutation of its decimal digits (leading zeros are allowed, so the arrangement is read as an ordinary number) and return the XOR of all those numbers. Permutations that produce the same digit arrangement are counted only once.

Input: A JSON object {"n": <non-negative integer>}.

Output: Return the XOR of every distinct digit permutation of n.

Examples

Example 1
Input: {"n":12}
Output: 25
Explanation: Arrangements 12 and 21 give 12 XOR 21 = 25.
Example 2
Input: {"n":11}
Output: 11
Explanation: Both arrangements are 11, so only one distinct value remains -> 11.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →