logo CodeStepByStep logo

bit_array_puzzle

Write a function named bit_array_puzzle that accepts as a parameter a reference to an array of integers. The array is guaranteed to be of length 2. One of its elements is guaranteed to store the value 0. The other element could be 0 or 1. Your task is to modify the array so that both indexes store 0. For example, if the array a contains {0, 1}, the call of bit_array_puzzle(a) should modify it to store {0, 0}.

The challenge in this problem lies in its constraints. You must not directly assign the value 0 to any index of the array. You are not allowed to use if or if/else statements, nor loops. Do not create any auxiliary collections such as arrays, etc. Also do not convert any integer into a string.

A correct solution can be done in O(1) time and space.

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.