Sorted permutation rank with repetition -interviewbit

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

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