VARANK Tech interview question

they asked me to do code and provide the solution for the problem