Class photograph

I did a 4d dp solution for this and it passed but when i submit the same code again … it aint passing all test case with giving a tle in one of the cases…
what is the approch for the ques?

@prabh1601 If a solution passed once it should pass again.
Please provide me your code in Coding Blocks IDE

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.