Short Problem Definition:
Count factors of given number N.
expected worst-case time complexity is O(sqrt(N));
expected worst-case space complexity is O(1).
This example can be found in the lesson document.
def solution(N): cnt = 0 i = 1 while ( i * i <= N): if (N % i == 0): if i * i == N: cnt += 1 else: cnt += 2 i += 1 return cnt
If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.