I got this question in Pharmeasy OA and the question was very unclear,I have also attached my solution in the screenshot that only passed 5 of 15 testcases. I dont know where I got wrong,The logic seems perfectly fine to me.