Doubt of the question Score_maximum_cgpa

question_link :

please provide editorial

seems to be a tricky question i am getting 10.5 points on 30
till now my approach has been to take a map and return the size of map-1 ( can take set alternatively)

so the question is bascially to find the max time the student becomes happy and the condition for that is that credits for previous subject should be less than present
so
for example
1 1 2 4 5 1 2 are the credits
so we can simply do the following

  1. arrange the single occurence of each digit
    like 1 2 4 5 1 2 1
    so first 4 character give happiness 3 the next 2 digits give happiness 1
    and since the last 1 does not have any greater digit in front it will not contribute to max happiness

another ex.
1 2 3 1 6 5 6 2 3
so we write all freq one in increasing order and then write those which have more than one occurence

1 2 3 5 6 1 2 3 6

so first 5 digits contribute to happiness 4+ next 4 digits give happiness 3
total 7

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.