How to solve this problem? Appreciate any help. I am being trying to solve in java but unable to do it. Let me know if there is any equivalent leetcode problem. Thank you in advance.