You are viewing a single comment's thread. Return to all comments →
java 8 solution
static int xoringNinja(int[] arr) { long or = 0; for (int j = 0; j < arr.length; j++) { or |= arr[j]; } BigInteger orb = new BigInteger(String.valueOf(or)); orb = orb.shiftLeft(arr.length - 1); orb = orb.mod(new BigInteger("1000000007")); return orb.intValue(); }
i observe following pattern 1) [1, 2, 3, 4] OR:7(111) sum:56(111000) 2) [4, 7, 2, 9] OR:15(1111) sum:120(1111000) 3) [14, 27, 22, 29] OR:31(11111) sum:248(11111000) 4) [14, 12, 2, 29] OR:31(11111) sum:248(11111000) 5) [12, 2, 29] OR:31(11111) sum:124(1111100) 6) [12, 29] OR:29(11101) sum:58(111010) 7) [12, 29, 213, 213123, 23322] OR:220127(110101101111011111) sum:3522032(1101011011110111110000) 8) [12, 29, 2, 1, 22, 7, 8, 9] OR:31(11111) sum:3968(111110000000) 9) [12, 0, 2, 1, 22, 7, 8, 9] OR:31(11111) sum:3968(111110000000)
Xoring Ninja
You are viewing a single comment's thread. Return to all comments →
java 8 solution
i observe following pattern
1) [1, 2, 3, 4] OR:7(111) sum:56(111000)
2) [4, 7, 2, 9] OR:15(1111) sum:120(1111000)
3) [14, 27, 22, 29] OR:31(11111) sum:248(11111000)
4) [14, 12, 2, 29] OR:31(11111) sum:248(11111000)
5) [12, 2, 29] OR:31(11111) sum:124(1111100)
6) [12, 29] OR:29(11101) sum:58(111010)
7) [12, 29, 213, 213123, 23322] OR:220127(110101101111011111) sum:3522032(1101011011110111110000)
8) [12, 29, 2, 1, 22, 7, 8, 9] OR:31(11111) sum:3968(111110000000)
9) [12, 0, 2, 1, 22, 7, 8, 9] OR:31(11111) sum:3968(111110000000)