I am going to ignore rotations in order to simplify the problem for your understanding. You have to enforce a series of inelastic relationship of the form
$$\vec{n}_{k}^\top (\vec{v}_i^+-\vec{v}_j^+) = 0 $$
where $\vec{n}_k$ is the normal direction of the $k$-th contact, and $i$, $j$ are the bodies this contact affects. The superscript $\phantom{c}^+$ denotes condition after the impact. You enforce this relationship with a series of $k$ impulses $J_k$ such that
$$ \vec{v}_i^+ = \vec{v}_i + \frac{\vec{n} J_k}{m_i} $$
$$ \vec{v}_j^+ = \vec{v}_j - \frac{\vec{n} J_k}{m_j} $$
Since it all has to happen at the same time it is best to form the problem with matrices.
Consider a Contact matrix $A$ where each column $k$ has +1 in the $i$-th row and -1 in the $j$-th row. For example $A = \begin{pmatrix}0&-1 \\ -1 & 0 \\ 0 & 0 \\ 1 & 1 \end{pmatrix}$ means there are two contacts, one between body 2 and body 4 and another between body 1 and 4. (actually each 0 and 1 are 2×2 for 2D or 3×3 for 3D zero and identity matrices).
The inelastic relationships are
$$N^\top A^\top v^+ =0$$ with the contact normal block diagonal matrix
$$ N = \begin{pmatrix} \vec{n}_1 & 0 & \cdots & 0 \\ 0 & \vec{n}_2 & & 0 \\ \vdots & & & \vdots \\ 0 & 0 & \cdots & \vec{n}_K \end{pmatrix} $$ and
$$ v = \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_N \end{pmatrix} $$
The momentum exchange is described by the relationship
$$ M v^+ = M v - A N J $$ where $M$ is the block diagonal mass matrix $M=\begin{pmatrix}m_1& & & \\ &m_2 & & \\& & \ddots & \\ & & & m_N\end{pmatrix}$ and $J$ the vector of impulses $J^\top=(J_1\,J_2\,\cdots J_K)$
To solve the problem we combine the momentum with the inelastic collisions to get
$$ v^+ = v - M^{-1} A N J $$
$$ N^\top A^\top \left(v - M^{-1} A N J \right) = 0$$
$$ \left(N^\top A^\top M^{-1} A N\right) J = N^\top A v $$
$$ \boxed{ J = \left(N^\top A^\top M^{-1} A N\right)^{-1} N^\top A^\top v }$$
Example
With $A$ as above (4 2D bodies, 2 contacts) and $\vec{v}_i = (\dot{x}_i,\dot{y}_i)^\top$, $\vec{n}_1=(1,0)^\top$, $\vec{n}_2 = (0,1)^\top$ then
$$ A = \left(\begin{array}{cc|cc} 0 & 0 & -1 & 0\\ 0 & 0 & 0 & -1\\ \hline -1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0\\ \hline 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ \hline 1 & 0 & 1 & 0\\ 0 & 1 & 0 & 1 \end{array}\right) $$
$$ N = \left(\begin{array}{c|c} 1 & 0\\ 0 & 0\\ \hline 0 & 0\\ 0 & 1 \end{array}\right) $$
$$ M = \left(\begin{array}{cc|cc|cc|cc} m_{1} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & m_{1} & 0 & 0 & 0 & 0 & 0 & 0\\ \hline 0 & 0 & m_{2} & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & m_{2} & 0 & 0 & 0 & 0\\ \hline 0 & 0 & 0 & 0 & m_{3} & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & m_{3} & 0 & 0\\ \hline 0 & 0 & 0 & 0 & 0 & 0 & m_{4} & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{4} \end{array}\right) $$
$$ v = \begin{pmatrix} \dot{x}_1 \\ \dot{y}_1 \\ \hline \dot{x}_2 \\ \dot{y}_2 \\ \hline \dot{x}_3 \\ \dot{y}_3 \\ \hline \dot{x}_4 \\ \dot{y}_4 \end{pmatrix} $$
$$ N^\top A^\top M^{-1} A N = \left(\begin{array}{cc} \frac{1}{m_{1}} + \frac{1}{m_{4}} & 0\\ 0 & \frac{1}{m_{2}} + \frac{1}{m_{4}} \end{array}\right) $$
$$ N^\top A^\top v = \begin{pmatrix} \dot{x}_4-\dot{x}_2 \\ \dot{y}_4 - \dot{y}_2 \end{pmatrix} $$
$$ J = \begin{pmatrix} \frac{\dot{x}_4-\dot{x}_2}{\frac{1}{m_2}+\frac{1}{m_4}}
\\ \frac{\dot{y}_4-\dot{y}_1}{\frac{1}{m_1}+\frac{1}{m_4}} \end{pmatrix} $$
Then
$$v^+ = v - M^{-1} A N J = \begin{pmatrix}
\dot{x}_1 \\
\frac{m_1 \dot{y}_1 + m_4 \dot{y}_4}{m_1+m_4} \\
\frac{m_2 \dot{x}_2 + m_4 \dot{x}_4}{m_2+m_4} \\
\dot{y}_2 \\
\dot{x}_3 \\
\dot{y}_3 \\
\frac{m_2 \dot{x}_2 + m_4 \dot{x}_4}{m_2+m_4} \\
\frac{m_1 \dot{y}_1 + m_4 \dot{y}_4}{m_1+m_4} \end{pmatrix} $$
Appendix
To include rotations follow the guidelines here:
I suspect this is semantics.
Two balls of clay thrown together in the ISS will stick together. Momentum is conserved, and kinetic energy is lost to sound, macroscopic deformation, and microscopic degrees of freedom. (We can do it in the airlock, so their no sound, if that is preferable).
And other example is 2 bowling balls with a spring contraption that locks at maximum compression. Momentum is conserved as the 2 balls move away as one, and kinetic energy is stored as (macroscopic) potential energy in the spring.
In both cases, the "missing" kinetic energy goes into internal energy of the final state object, and it can be macroscopic and/or microscopic.
I have ignored angular momentum. The collisions need to be perfectly aligned for the final object to have have zero rotation, and hence zero rotational energy. Since "perfect alignment" is impractical, one can never achieve this.
Now the semantics: If the rotational energy is defined as "kinetic energy of the final state", then one cannot achieve a perfectly inelastic collision. There were always be some kinetic energy above the absolute minimum allowed by conservation of momentum.
If the rotational energy is defined as "internal energy of the final state" (rotational excitation), then it is no different from a loaded spring, and a perfectly inelastic collision is achieved.
Best Answer
In general, the elasticity of a collision is dependent on the properties of the colliding objects. In a perfectly elastic collision, no kinetic energy is dissipated, which means the collision creates no heat, no sound, etc. In a perfectly inelastic collision, the maximum possible amount of kinetic energy is dissipated as heat, sound, etc. This corresponds to the two particles sticking together after the collision.
In real life, most collisions are neither perfectly elastic nor perfectly inelastic, but rather somewhere in the middle. (One major exception to this is gas molecule collisions, which are perfectly elastic.) Some objects collide nearly perfectly elastically, such as billiard balls or steel ball bearings, while others collide nearly perfectly inelastically, such as balls of putty or mud. Without knowing the specific properties of the colliding objects (such as their elasticity, etc.), it is impossible to predict how elastic a collision will be.