Codility 'OddOccurrencesInArray' Solution

Martin Kysel · December 11, 2014

Short Problem Definition:

Find value that occurs in odd number of elements.

OddOccurrencesInArray

Complexity:

expected worst-case time complexity is O(N)

expected worst-case space complexity is O(1)

Execution:

This problem can be found in many algorithm books. A xor A cancels itself and B xor 0 is B. Therefore A xor A xor B xor C xor C is B.

Solution:

def solution(A):
    missing_int = 0
    for value in A:
        missing_int ^= value
    return missing_int

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.