Building a matrix by applying XOR rules
Time complexity is \$O(nm)\$. Obviously it is bound to TLE. There is an \$O(n)\$ solution, based on the following observations:


\$ x \oplus x = 0\$
\$ x \oplus y = y \oplus x\$


Let's say your initial row is a b c d e f. The next row will be a^f b^a c^b d^c e^d f^e. The second next is more interesting: the first element is a^f ^ f^e = a^e, the second is a^f ^ b^a = b^f, etc.

In general (prove it by induction), \$k\$'th row consists of \$a_i \oplus a_{i-k}\$ (where the last index is taken modulo n). Notice that the \$n\$'th row is all zeroes, and so are all the subsequent rows.
The code is extremely hard to follow. num is only used once - may be not have it at all?

    last = xor[0];

    for(int i=0 ; i&lt;xor.length ; i++){
        if(i&lt;xor.length-1){
            xor[i] = xor[i]^xor[i+1];
        }
        if(i==xor.length-1){
            xor[i] = xor[i]^last;
        }
    }


Notice that i == xor.length - 1 is true exactly once, at the predictable i, yet you test it at each iteration. Lift it out of the loop:

    last = xor[0];
    for(int i=0 ; i&lt;xor.length - 1; i++){
        xor[i] = xor[i]^xor[i+1];
    }
    xor[i] = xor[i]^last;