We need O(log N) bits to represent N. It can’t be O(1)

# Space Copmlexity

for space complexity it is only assigning values for a & b. No new memory is allocated when the loop is executed that is why space complexity is O(1).

Variable used here are a, b, i , j, k, N.

For normal variables, space complexity is O(1).

For arrays, 1D -> space complexity is O(n)

2D -> space complexity is O(n^2)…and so on.

For this particular problem,

a -> space complexity is O(1)

b -> space complexity is O(1)

i -> space complexity is O(1)

j -> space complexity is O(1)

k -> space complexity is O(1)

N -> space complexity is O(1)

Only normal variables are used so over all space complexity will be O(1).