He said time complexity would be O(log n), and the interviewer confirmed it.

I thought it is O(n), because the more digits in the integer, the more loops done by “while” loop, so the more the input size of this function, the more loops will be done.
integer of 3 digits, will take 3 loops
integer of 4 digits, will take 4 loops
and so on.

I don’t why I thought about it as number of digits, I feel something wrong in my way, but I don’t know how to think of increasing input when it is just a number not a size of something.

That is exactly correct.
Your “failure” is just that the input is “n” not “digits in n”.
So how do you calculate the number of digits in a given number base10? Well you calculate the logarithm of the number to the base → so it’s log10(n).

Then that’s some advanced math, but the difference of the base in logarithm is just multiplication with a constant value.

log2(n) === log10(n) * ln(10)/ln(2)

But because in Time-Complexity multiplication with a constant value doesn’t matter, you just use “log(n)”.

Finfact: because the base can be changed, it doesn’t matter that I used ln(x) for the transformation → I could have used any base.

@Jagaya
I am trying to understand your words, but didn’t get it yet, revising some stuff about logarithms though, but I wanted to ask you if you may write again in different expressions maybe I can connect some dots.