A infinitely long stream of 0's and 1's are coming ,you have to find out whether number formed so far is divisible by 3 or not.
i tried it by finding decimal equivalent of binary number and then summing all the digits and finding if that sum is divisible by 3 or not. but i know it is wrong method because number is infinitely long so after some time number will be out of range. So what would be the approach for this.
another approach would be to find out even positions set bits and odd positions set bits and if difference of total number of set bits for odd and even positions is divisible by 3 then number will be divisible by 3. but here also after sum time number will be out of range.
is there any better approach?