Help me solve this Problem

https://www.hackerrank.com/contests/pass-the-baton-2023-offline-prelims/challenges/dd-and-numbers