when i tried the code with list, it worked but w/o list, it is failing a test case.
Simple input code
Hey @yashikakhurana00, we have provided the test cases as well, try opening the test case and running it directly on test case to figure out the mistake.
Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.