Help in solving "Counting permutations" problem from hackerearth?

algorithm
coin-change
dps
hackerearth

#1

Anyone please help me in solving THIS PROBLME based on counting no. of permutations.

**NOTE : **

Please don’t propose the dp (coin change) problem, I have already solved it using that, I suspect there might be some trick to solve this question.