Unable to implement and understand the logic

Please can you send the code along with the logic