# Construct a array using following rules

Consider there is a array $$a$$ of length $$n$$ , $$a=[a_i ,0 \leq i \leq n]$$ and all $$a_i>0$$ and I need to construct a array $$b$$ of length $$n$$ (if possible) , $$b=[b_i , 0\leq i \leq n]$$ .Rules for making array b is all $$1\leq b_i\leq 5$$ .

Consider $$j=i+1$$ ,if $$a_j>a_i$$ then $$b_j>b_i$$ ,if $$a_j then $$b_j and if $$a_i=a_j$$ then $$b_i \neq b_j$$ .

Example : $$a=[2,3,4]$$ then $$b$$ can be $$[1,2,3]$$ ,any $$b$$ is $$accepted$$.

My approach is to use a simple $$dynamic$$ $$programming$$ ,$$dp[i][j]$$ where i will check if first $$i$$ elements of $$b$$ can be formed if $$b_i=j$$ where $$0 if it is possible $$dp[i][j]=1$$ else ,$$dp[i][j]=0$$ .By this method i could find if answer exits but i could not find the array $$b$$ ,I know array $$b$$ can be formed by depth first search as we can see states are connected by i have no idea after that.Could anyone help me how to use dfs on this question.