Not sure why some are suggesting O(log n). Binary search only works on an ordered set. These numbers are not ordered. The fastest you can possibly achieve this is O(n). You must iterate through all the digits to ensure even the very last digit is within the rules.
O(n log n) solution, this can be completed in O(n).
O(n log n) solution. Not really sure I'd flag that as best practice.
Not sure why some are suggesting O(log n). Binary search only works on an ordered set. These numbers are not ordered. The fastest you can possibly achieve this is O(n). You must iterate through all the digits to ensure even the very last digit is within the rules.
Note due to formating issues codewars changes some of my * to italics.
This comment is hidden because it contains spoiler information about the solution