Efficient algorithm to compare arrays problem
You can write $x$ and $y$ in binary as
\begin{align}
x&amp;=x_{M-1} \ldots x_0 \\
y&amp;=y_{M-1} \ldots y_0
\end{align}
(This is exactly the contents of your arrays.)
Since $x \neq y$, there must be a first bit (from the left) at which they differ. Say that this bit is $x_i \neq y_i$. Since $y &gt; x$, we know that $y_i = 1$ and $x_i = 0$. Thus
\begin{align}
x &amp;= x_{M-1} \ldots x_{i+1} 0 x_{i-1} \ldots x_0 \\
y &amp;= x_{M-1} \ldots x_{i+1} 1 y_{i-1} \ldots y_0
\end{align}
The following two integers are in the range $x,\ldots,y$:
\begin{align}
&amp;x_{M-1} \ldots x_{i+1} 0 1 \ldots 1 \\
&amp;x_{M-1} \ldots x_{i+1} 1 0 \ldots 0
\end{align}
This shows that if you take the AND of all integers from $x$ to $y$, you get
$$
x_{M-1} \ldots x_{i+1} 0 0 \ldots 0
$$