Sort by

recency

|

47 Discussions

|

  • + 0 comments
        result|=arr[i];
        int ans=1;
        for(int i=0;i<n-1;i++){//use this method for calculting power of 2
            ans=(ans*2)%mod;
        }
        cout<<(result*ans)%mod<<endl;
    
  • + 0 comments
    #python
    def xoringNinja(arr):
        result = 0
        for x in arr:
            result =result | x
        return result*(2**(len(arr)-1)) % (10**9 + 7)
    		
    
  • + 0 comments

    Please assist me in that only half of my test cases pass and the other half krunker provide a runtime error.

  • + 0 comments

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

  • + 0 comments

    I don't know how it works but i observed the following pattern: 1, 2, 4, 8 = 120 1, 2, 4, 8, 6(4+2) = 240 1, 2, 4, 10(8+2), 8 = 240 1, 2, 4, 10, 6, 8, 3 = 960 = 120 * BigInteger.Pow(2, arr.count - 4(1 2 4 8 ) //you should use the above examples to solve it rather than look at the code :) //it took me a lot of time and i changed my code several times because i didn't use BigInteger and i was right from the beginning. public static int xoringNinja(List arr) //C# {

        List<int> list = new List<int>();
        int max = 0;
        int i = 1;
        foreach(int x in arr)
        max = (max | x);
        if(max == 0)
        return 0;
        while(max > i)
        {
           i = i << 1;
           if(i == (1 << 30))
           break;
        }
        for(i = i; i != 0; i = i >> 1)
        {
            if((max - i) >= 0)
            {
            list.Add(i);
            max -= i;
            }
        }
        max = 0;
        foreach(int x in list)
        max += x;
    
        BigInteger b = BigInteger.Multiply(max, BigInteger.Pow(2, list.Count-1));
        if((arr.Count - list.Count) < 1) //0
        {
           for(i = list.Count - arr.Count;i != 0; i--)
           b = b/2;
        }
        else
        {
        b = BigInteger.Multiply(b, BigInteger.Pow(2, arr.Count - list.Count));
        b = b % 1000000007;
        }
        return (int)b;
    }