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.
The filter should be first to speed the iteration of the map
That isn't true, it works in that case because replace replaces all instances of the word on each call, but the foreach loop has the unmodified members of the array created using split.
The real issue is if there are words that also contain their reversals inside of the array. For example,
"12345 54321 12345"
produces
"54321 54321 54321"
because of how replace searches the entire string for all instances of the CharSequence to change, while the foreach loop will have the old data.
This solution can benefit from the n /= 10 trick as well as having a wrap-around index for your remainders array