Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yes, I initially assumed global variables because this is one of the most common cause of complaints about "works for me but not here", and additionally I misunderstood the "there is exact single input and exact single output" part. Only later I checked your solution and found actual bug.
This is wrong, because if there is 10 basic tests, Codewars run all 10 of them. If you run only one of them locally, you will not detect issues like, for example, use of stale values of global/static variables (I am not saying that this is your problem, but it's one of the reasons when users complain that their solution works locally, but not on CW).
Specifically for cases like this one, when users blame their problems on the platform instead on their own code, I ceated a bot which helps beginners. I run it on your solution and it said:
PS. I usually try to avoid spoilers when supporting users but this bug might be indeed difficult to reproduce, and I think it's worth to close the argument sooner than later)
This is not a valid conclusion, but it's very often made by beginners. Problem is how you run your solution locally, because you run it differently than the site. What you need to try is to run your solution more than once for different inputs.
The site doesn't run code like that.
Your code has a different flaw you have not yet detected.