XOR key Discussions | Algorithms | HackerRank

Sort by

recency

|

48 Discussions

|

  • + 0 comments

    This is my code but I am getting timeout exceeded and I am not able to optimize further

    def xorKey(x, queries):
        # Write your code here
        lst=[]
        for j in queries:
            a,l,r=j
            y=filter(lambda i:l<=i and i<=r,x)
            res=set([a^k for k in y])     
            lst.append(max(res))     
        return lst
    
  • + 0 comments

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

  • + 0 comments

    how to find xor key from xor? i have some encoded xor string but idk how to decode it, this is my school assigment

    pFYK+3fxjlh+NRQAWkljQgBT/dDqzoa4pA/ku/Gz9e4=

  • + 0 comments

    https://pastebin.com/51RRGvGL Do check my code for any doubts regarding this question simply using a trie solved this question. Just maintain a vector at every node whose number indexes are on the way and check whether to take such path there exists a number in range l to r using a lower_bound if there continue such maximum path or else the other. {all those indexes of numbers will be sorted because of the increasing way of adding these numbers to trie} Max Space and time:O(16*N)

  • + 1 comment
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'xorKey' function below.
    #
    # The function is expected to return a LONG_INTEGER_ARRAY.
    # The function accepts following parameters:
    #  1. LONG_INTEGER_ARRAY x
    #  2. 2D_LONG_INTEGER_ARRAY queries
    #
    
    def xorKey(x, queries):
        res=[]
        for i in queries:
            maxi=0
            a,l,r=i[0],i[1],i[2]
            if l==r : maxi=a^x[l-1]
            else :  
                for j in range(l,r+1):
                    if j<len(x):
                        xori=a^x[j-1]
                        if xori>=maxi : 
                            maxi=xori 
            res.append(maxi)
        return res
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(input().strip())
    
        for t_itr in range(t):
            first_multiple_input = input().rstrip().split()
    
            n = int(first_multiple_input[0])
    
            q = int(first_multiple_input[1])
    
            x = list(map(int, input().rstrip().split()))
    
            queries = []
    
            for _ in range(q):
                queries.append(list(map(int, input().rstrip().split())))
    
            result = xorKey(x, queries)
    
            fptr.write('\n'.join(map(str, result)))
            fptr.write('\n')
    
        fptr.close()