logo CodeStepByStep logo

occurs_odd

Write a function named occurs_odd that accepts as a parameter an array of integers and its length, all of which occur an even number of times except for a single value that occurs an odd number of times. Your task is to find and return the integer value that occurs an odd number of times. For example, if the array a contains {3, 7, 3, 8, 3, 7, 3}, the call of occurs_odd(a, 7) should return 8.

You must solve this problem using bitwise operators. Do not create any auxiliary collections such as arrays, etc. Also do not convert any integer into a string. An optimal solution can solve this problem with O(1) memory usage and in O(N) time where N is the number of elements in the array.

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.