how to count number of digits in O(1)?

I want to count number of digits in O(1)
And how is it possible?

1 Like

convert the integer to String (rather take the input as String) … length of the string is the number of digits in the NUMBER.

2 Likes

This may help

More over you can do this while taking input simultaneously when using fast input methods like getchar() .

1 Like

Bro , you could easily get these things in one google search

Anyway the answer is log10(n)+1

2 Likes