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.
Not O(log N)
you are still sorting wich is O(N log N)
And O(2N) is O(N), in the usual notation.
How?
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.
This comment is hidden because it contains spoiler information about the solution
Note there is no formattign issues is formatting is used: https://docs.codewars.com/references/markdown#code-block
i need to use malloc
Note due to formating issues codewars changes some of my * to italics.
This comment is hidden because it contains spoiler information about the solution