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.
Readable and ideomatic.
Not performant for large arrays. But that was not required in the description.
So "best practice" from me
Great. Performs for big arrays. And readybility is good too, whenever I prefer a variable like 'offset' for 'i+1'.
Contrary to other comments, I like this soluluton. Of course it doesn't perform on large arrays. But there is no "large array warning" in the description. And the code is clear, readable and ideomatic. So for me the high score on 'best practices' is deserved.
I struggled with the same problem with the spaces and like your workaround. Clever.
The more common and probably better solution is to use split(' ') instead of split().
Takes care of the spaces and works even if the word distances are not consistent.
Algorithm is efficient because it stops early. Code is good to read despite the extra lines for the early stop. I like it.