14. Xoring and Clearing
The problem can be found at the following link: Question Link
My Approach
For printArr function:
Iterate through the array from index 0 to n-1.
Print each element of the array followed by a space.
Print a newline character after printing all elements.
For setToZero function:
Iterate through the array from index 0 to n-1.
Set each element in the array to zero using direct assignment.
For xor1ToN function:
Iterate through the array from index 0 to n-1.
For each element at index i, perform a bitwise XOR operation with i.
Update the element in the array with the result of the XOR operation.
Time and Auxiliary Space Complexity
Time Complexity:
O(N)
, whereN
is the size of the array.Auxiliary Space Complexity: O(1) - No extra space is used; the space complexity remains constant.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated