Algorithmic is not a trivial skill. You have to understand clearly the problem and be able to reformulate (which you've done well here). Then you need to know the vocabulary that will help you. Codewar is an excellent resource to polish that skill. I liked edabit.com for this also.
The refactored code is actually the solution in codewars! 😅, I'll check out edabit, thanks!!
We’re a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.