Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
The time complexity analysis seems incomplete. It only analyses the time it take...

hj3yoo

Feb 22, 2022

The time complexity analysis seems incomplete. It only analyses the time it takes to calculate the next sequence number (sure, that time is bound to get smaller over iteration, but the analysis doesn't mention it).

I would recommend looking at the Leetcode solution for more detailed analysis: https://leetcode.com/problems/happy-number/solution/

11

0

Comments
Comments
Miguel
Miguel 2 years ago

Highly recommend reading both approach 1 and approach 2 (in that order), as approach one explains a lot of the math involved here.

Miguel
Miguel 2 years ago

In fact, I would encourage Design Gurus to consider taking a look at the explanation there and consider revising their own explanation for the sake of clarity.

Shubham Vora
Shubham Voraa year ago

Here's a brief explanation:

  • findSquareSum(num) Complexity: For a number num, calculating the sum of squares of its digits takes O(log N) time, where N is the number. This is because num has log10(N) digits.

  • Cycle Detection: The function eve...

On this page