Intuition
The basic idea for our code is that - (A + B) & C
. When A & B == 0
, there are no digits that are same. So, A + B
will have all the ones from both numbers A and B - they would have sort of merged.
Basically, the criteria they have mentioned of bitwise AND of two consecutive elements to be 0, is cumulative. To check, we can maintain a window sum and shrink window till the new number we are checking does not result in zero.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are sliding a window over the array so this way every element is worked on only once.
-
Memory
The memory usage is since we are not using any extra data structure.
— A