Google Coding Interview Question - Happy Number (Cycle Detection) [LeetCode]

preview_player
Показать описание
Check out my interview prep platform for learning the patterns!

Here is a step by step guide to the LeetCode problem Happy Number asked at Google.

This problem involves the use of Floyd's Cycle Finding Algorithm. The key idea behind the problem is we need to create nodes (which are integers) that have all their digits squared and summed up. If our tortoise pointer is equal to 1 by the end of finding a cycle, that means we have found a happy number!

TIMESTAMPS
----------------------------------------------------------------------------------------------------------------
00:00:00 - problem description
00:01:31 - cycle detection algorithm walk through
00:04:36 - node generation walk through
00:08:26 - code walk through
00:12:10 - time/space complexity explanation
Рекомендации по теме
Комментарии
Автор

Extremely well explained. You are great!

christopherraris
Автор

Good video, but the time complexity is not explained properly. Just because the tortoise and hare meet somewhere in the middle doesn't mean it's log(n).
It's actually much more complicated and deals with the number of digits of the input with the number of values the cycle can reach. Would have been better if that was touched upon.

justsurajp
Автор

This is simply n simple amazing explanation wow, love it such a clean code.

projectsdb
Автор

Good explanation .. you deserve more views

vinprabhu
Автор

I saw this question today. Is this better than having a hashset to check whether a sum is already visited, that also can detect loops, right ?

shaheennamboori
Автор

I still do not understand why the time complexity is log n ?

yuecheng
welcome to shbcf.ru