Finding row wise sum of transpose of hv-convex binary matrix
A non-increasing sequence of integers is known as a partition. The operation you are describing is known as conjugation. Given a partition $\lambda_1,\ldots,\lambda_n$, you can compute its conjugate $\lambda'_1,\ldots,\lambda'_m$ as follows:


Initialize a pointer $i$ at $n$.
Set $\lambda'_1 = i$.
Advance $i$ backwards until $\lambda_i \geq 2$.
Set $\lambda'_2 = i$.
Advance $i$ backwards until $\lambda_i \geq 3$.
Set $\lambda'_3 = i$.
...
Stop once $i = 1$.


As an example, here is how you apply this algorithm on $4,3,2,2,1$.
$$
\begin{align*}
&amp;\begin{array}{ccccc}
4 &amp; 3 &amp; 2 &amp; 2 &amp; 1 \\
&amp;&amp;&amp;&amp; \uparrow \\
&amp;&amp;&amp;&amp; 5
\end{array} \\\hline
&amp;\begin{array}{ccccc}
4 &amp; 3 &amp; 2 &amp; 2 &amp; 1 \\
&amp;&amp;&amp; \uparrow \\
&amp;&amp;&amp; 4
\end{array} \\\hline
&amp;\begin{array}{ccccc}
4 &amp; 3 &amp; 2 &amp; 2 &amp; 1 \\
&amp; \uparrow \\
&amp; 2
\end{array} \\\hline
&amp;\begin{array}{ccccc}
4 &amp; 3 &amp; 2 &amp; 2 &amp; 1 \\
\uparrow \\
1
\end{array}
\end{align*}
$$
It might happen that at some point $i$ doesn't advance at all. This is what happens if we apply this algorithm on $5,4,2,1$:
$$
\begin{align*}
&amp;\begin{array}{cccc}
5 &amp; 4 &amp; 2 &amp; 1 \\
&amp;&amp;&amp; \uparrow \\
&amp;&amp;&amp; 4
\end{array} \\\hline
&amp;\begin{array}{cccc}
5 &amp; 4 &amp; 2 &amp; 1 \\
&amp;&amp; \uparrow \\
&amp;&amp; 3
\end{array} \\\hline
&amp;\begin{array}{cccc}
5 &amp; 4 &amp; 2 &amp; 1 \\
&amp; \uparrow \\
&amp; 2
\end{array} \\\hline
&amp;\begin{array}{cccc}
5 &amp; 4 &amp; 2 &amp; 1 \\
&amp; \uparrow \\
&amp; 2
\end{array} \\\hline
&amp;\begin{array}{cccc}
5 &amp; 4 &amp; 2 &amp; 1 \\
\uparrow \\
1
\end{array}
\end{align*}
$$