Sansa and XOR

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def sansa_and_xor(arr):
        #Time complexity: O(n)
        #Space complexity (ignoring input): O(1)
        #A number will appear in {(index+1)*(n-index)} subsequences
        #In case arr.len() is par, the appearences of any number will be par as well
        xor_value = 0
        for index in range(0, len(arr)):
            frequency_number = (index + 1) * (len(arr) - index)
            if frequency_number % 2 != 0:
                xor_value ^= arr[index]
    
        return xor_value