Загрузка страницы

GOOGLE - HAPPY NUMBER (LEETCODE)

This is one of Google's most commonly asked interview questions according to LeetCode (2019)! Happy Number coding solution. If you give me 5 minutes you'll thank me if this appears during your Google interview! Coding Interviews Happy Number (LeetCode) question and explanation.

DISCORD CHANNEL
----------------------------------------------------------------------------------------------------------------
To join the Discord channel use the following link and join the "Member" tier: https://www.patreon.com/KevinNaughtonJr
In this Discord channel, you will be able to...
1. Ask me questions directly (as well as other members)
2. Ask about and discuss previous interview experiences
3. Find mock interview partners
4. Share helpful videos for interview preparation, and more!

This question is commonly asked by the following companies: Google, Facebook, Apple, JPMorgan, VMWare, and Nutanix.

Link to problem: https://leetcode.com/problems/happy-number/

Intuition behind solution: while our number is not a happy number (n != 1) we continue summing the squares of the digits of n. To do this we store the current value of n and while it is not equal to zero we grab the last number of current (current % 10), multiply it by itself and add it to our sum. Once we have iterated through all the digits of current, we check if our new sum is already contained in our "seen" hashset, if it is, we return false (this means we are in a cycle). Otherwise, we add the current sum to our "seen" hash set and set our n to our new sum. If our outer loop ever breaks, we return true.

SOCIAL
----------------------------------------------------------------------------------------------------------------
Support me on Patreon: https://www.patreon.com/KevinNaughtonJr
Follow me on Twitter: https://twitter.com/KevinNaughtonJr
Follow me on Instagram: https://instagram.com/kevinnaughtonjr/
Follow me on GitHub: https://github.com/kdn251

MUSIC
----------------------------------------------------------------------------------------------------------------
Leave Em Cold by @lau_mcgill
https://soundcloud.com/laurentiusmcgill/leave-em-cold

#coding #interviews #softwareengineering

Видео GOOGLE - HAPPY NUMBER (LEETCODE) канала Kevin Naughton Jr.
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
25 апреля 2019 г. 6:55:26
00:06:42
Яндекс.Метрика