XOR Subsequences Discussions | Algorithms | HackerRank

Sort by

recency

|

19 Discussions

|

  • + 0 comments

    Due to time error, I don't know how to solve this...

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    from collections import Counter
    from operator import itemgetter
    #
    # Complete the 'xorSubsequence' function below.
    #
    # The function is expected to return an INTEGER_ARRAY.
    # The function accepts LONG_INTEGER_ARRAY a as parameter.
    #
    
    def xor_sub(arr, n):
        
        result = []
        for i in range(n):
            result.append(arr[i])
        for j in range(2, n+1):
            for i in range(len(arr) - j + 1):
                a = arr[i]
                for k in range(1,j):
                    a ^= arr[i+k]
                result.append(a)
        return result
                
        
    
    def maxOccur(A):
        count = Counter(A)
        sorted_count = sorted(count.items(), key=lambda x: (-x[1],x[0]))
        return sorted_count[0]
    
    
    def xorSubsequence(a):
        # Write your code here
        l = []
        l = xor_sub(a,len(a))
        print(l)
        # check the frequency
        # a = Counter(l)
        # a_sorted = sorted(a.items(),key=itemgetter(1), reverse=True)
        # a_sorted = sorted(a_sorted)
        ti = maxOccur(l)
        retL = []
        retL.append(ti[0])
        retL.append(ti[1])
        return retL
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        a_count = int(input().strip())
    
        a = []
    
        for _ in range(a_count):
            a_item = int(input().strip())
            a.append(a_item)
    
        result = xorSubsequence(a)
    
        fptr.write(' '.join(map(str, result)))
        fptr.write('\n')
    
        fptr.close()
    
  • + 0 comments

    Here is XOR Subsequences problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-XOR-subsequences-problem-solution.html

  • + 0 comments

    Thanks mate, the same problem I had.Great explanation. wazifa to get your love back

  • + 1 comment

    Can anybody explain why is this a convolution problem? I can't understand why

  • + 1 comment

    I can't get the Python3 example to work at all, even if I just return the expected result it still says it fails:

    def xorSubsequence(a):
        return "1 3"