Solving HackerRank Problem Sum vs XOR in Java.

Problem

Complete the sumXor function in the editor below. It should return the number of values determined, as an integer.

sumXor has the following parameter(s).

Full Problem Description: https://www.hackerrank.com/challenges/sum-vs-xor/problem

Solution

Initial Thoughts: Brute force would be to check the condition

for all numbers between 0 -> n and keep a

counter of which ones satisfied it. To make

this faster, we can simply count the number

of zeros after converting n to a binary number.

Time Complexity: O(n log(n)) //It takes n log(n) time to convert to binary using two's division

Space Complexity: O(1) //There is no ddynamically allocated variables

Credit: @github.com/RyanFehr