28. Subset XOR
β GFG solution to the Subset XOR problem: find maximum size subset from 1 to n with XOR equal to n using mathematical XOR pattern recognition. π
π§© Problem Description
π Examples
Example 1
Input: n = 4
Output: [1, 2, 3, 4]
Explanation: We choose all the elements from 1 to 4. Its XOR value is equal to n (1^2^3^4 = 4).
This is the maximum possible size of the subset.Example 2
Input: n = 3
Output: [1, 2]
Explanation: 1 ^ 2 = 3. This is the smallest lexicographical answer possible with maximum
size of subset i.e 2.π Constraints
β
My Approach
XOR Pattern Recognition
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated