O(log10(N)) β In every iteration we are dividing N by 10 (equivalent to the number of digits in N).
O(log10(N))
log10nlog_{10} nlog10βn is the standard mathematical notation for the number of digits/iterations, where nnn is the value of the input number.
But in interview, be careful, tell both ways
When nnn is the number , since we are dividing the number by 10 at every step the time complexity follows a logarithmic scale, then the TC is log10nlog_{10}nlog10βn
When DDD is considered as number of digits, then the time complexity can be represented as O(D)O(D)O(D)
Last updated 1 month ago