Here, we are asked to "Avoid Deadlock" and Bankers Algorithm is the algorithm for this.

The crux of the algorithm is to allocate resources to a process only if there exist a **safe sequence after** the allocation. i.e., after allocating the requested resources there exist a sequence of execution of the processes such that deadlock would not happen. There can be multiple safe sequences but we need to get any one of them to say that a state is safe.

Now coming to the given question, first lets make the $\text{NEED}$ matrix which shows the future need of all the processes and can be obtained by $\text{Max} - \text{Allocation}.$$$\overset{\Large{\text{Max}}}{\begin{array}{llll} &r_{0} & r_{1} & r_{2} & r_{3} \\ p_0& 0 & 0 & 1 & 2 \\ p_1& 1 & 7 & 5 & 0 \\ p_2&2 & 3 & 5 & 6 \\ p_3& 0 & 6 & 5 & 2 \\ p_4& 0 & 6 & 5 & 6 \\ \end{array}} - \overset{\Large{\text{Allocation}}}{\begin{array}{llll} & r_{0} & r_{1} & r_{2} & r_{3} \\ p_{0} & 0 & 0 & 1 & 2 \\ p_{1} & 1 & 0 & 0 & 0 \\ p_{2} & 1 & 3 & 5 & 4 \\ p_{3} & 0 & 6 & 3 & 2 \\ p_{4} & 0 & 0 & 1 & 4 \\ \end{array}} = \overset{\Large{\text{Need}}}{\begin{array}{llll} &r_{0} & r_{1} & r_{2} & r_{3} \\ p_0& 0 & 0 & 0 & 0 \\ p_1& 0 & 7 & 5 & 0 \\ p_2&1 & 0 & 0 & 2 \\ p_3& 0 & 0 & 2 & 0 \\ p_4& 0 & 6 & 4 & 2 \\ \end{array}}.$$

Since $P_0$ does not require any more resource we can finish this first releasing $1$ instance of $r_2$ and $2$ instances of $r_3.$ Thus our $\text{Available}$ vector becomes $$\begin{bmatrix}1&5&2&0\end{bmatrix}+\begin{bmatrix}0&0&1&2\end{bmatrix} =\begin{bmatrix}1&5&3&2\end{bmatrix}.$$

Now, either $p_2$ or $p_3$ can finish as both their requirements are not greater than the $\text{Available}$ vector. Say, $p_2$ finishes. It releases $\begin{bmatrix}2&3&5&6\end{bmatrix}$ and our $\text{Available}$ becomes $$\begin{bmatrix}1&5&3&2\end{bmatrix}+\begin{bmatrix}2&3&5&6\end{bmatrix} =\begin{bmatrix}3&8&8&8\end{bmatrix}.$$

Now, any of $p_1,p_3,p_4$ can finish and so we do not need to proceed further to determine that the state is safe. One of the possible safe sequence is $$p_0-p_2-p_1-p_3-p_4.$$