Sorted permutation rank with repetitions - interviewbit

I am not able to solve this. Please help in this

ques - https://www.interviewbit.com/problems/sorted-permutation-rank-with-repeats/


my solution


the article i used to understand this solution