Ugly Number - Leetcode 263 - Python

Ғылым және технология

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🐦 Twitter: / neetcode1
🥷 Discord: / discord
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 CODING SOLUTIONS: • Coding Interview Solut...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
🌲 TREE PLAYLIST: • Invert Binary Tree - D...
💡 GRAPH PLAYLIST: • Course Schedule - Grap...
💡 BACKTRACKING PLAYLIST: • Word Search - Backtrac...
💡 LINKED LIST PLAYLIST: • Reverse Linked List - ...
💡 BINARY SEARCH PLAYLIST: • Binary Search
📚 STACK PLAYLIST: • Stack Problems
Problem Link: leetcode.com/problems/ugly-nu...
0:00 - Read the problem
1:40 - Drawing Explanation
8:44 - Coding Explanation
leetcode 263
This question was identified as a facebook interview question from here: github.com/xizhengszhang/Leet...
#prime #number #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.

Пікірлер: 30

  • @youngee9403
    @youngee94032 жыл бұрын

    there are times that i wonder if im being punished for skipping all my math classes during undergrad

  • @NeetCode

    @NeetCode

    2 жыл бұрын

    I feel the same sometimes lol

  • @user-us7rg4cd6p

    @user-us7rg4cd6p

    2 ай бұрын

    There are times I wonder if I am being punished for not studying Computer Science Major but trying to be a software programmer.. lol

  • @littlecatboybuddy
    @littlecatboybuddy11 ай бұрын

    I watch entire videos! Because I'm a beginner so the coding section is really helpful! Thank you for the great explanation :)

  • @harshaggarwal1967
    @harshaggarwal19672 жыл бұрын

    You just made it quick and easy.. Thanks!!

  • @NeetCode

    @NeetCode

    2 жыл бұрын

    Glad it helped!

  • @swatiaga8554
    @swatiaga85542 жыл бұрын

    you can also add one more condition at while loop that n!= 0 otherwise the loop will be infinite.

  • @sudluee
    @sudluee2 жыл бұрын

    i think the worse case time complexity is O(log(2)n) that's if n is only divisible by 2.

  • @jideabdqudus
    @jideabdqudus2 жыл бұрын

    My Favorite YT chanel, don't ask me why

  • @ambujhakhu7531

    @ambujhakhu7531

    2 жыл бұрын

    why

  • @playonce4186

    @playonce4186

    2 жыл бұрын

    @@ambujhakhu7531 dont worry why he said

  • @shavvasatya7131

    @shavvasatya7131

    Жыл бұрын

    But how

  • @Gerald-iz7mv
    @Gerald-iz7mv11 ай бұрын

    hi - is there a leetcode playlist for this as well?

  • @maamounhajnajeeb209
    @maamounhajnajeeb209 Жыл бұрын

    Thanks

  • @Rishabhsingh-ev7ii
    @Rishabhsingh-ev7ii2 жыл бұрын

    i think u r from mars ur every video is educative

  • @fsteve6443
    @fsteve64432 жыл бұрын

    the GOAT uploaded

  • @BB8_CA

    @BB8_CA

    2 жыл бұрын

    As aways!

  • @_tan2112
    @_tan2112 Жыл бұрын

    Helpfull

  • @duckieace
    @duckieace2 жыл бұрын

    What happens if n is 1. This code seems like it return it as True even though the prime number of 1 is not 2 3 or 5. shouldn't it be if n

  • @spaceface2288

    @spaceface2288

    2 жыл бұрын

    if n == 0: return False while n % 2 == 0: n = n / 2 while n % 3 == 0: n = n / 3 while n % 5 == 0: n = n / 5 return n == 1

  • @sahanar4805

    @sahanar4805

    2 жыл бұрын

    +1

  • @harshaggarwal1967

    @harshaggarwal1967

    2 жыл бұрын

    1 has no prime factors, therefore all of its prime factors are limited to 2,3 and 5..so we can take it as ugly number.. Hence return true for this case..

  • @monkeyDluffy-sd3zp
    @monkeyDluffy-sd3zp Жыл бұрын

    but the test case says 20 is an ugly number.

  • @monkeyDluffy-sd3zp
    @monkeyDluffy-sd3zp Жыл бұрын

    20 is not considered an ugly number. An ugly number must only be divisible by 2, 3, or 5, but 20 is also divisible by 4, which is not among the allowed prime factors. -source chatgpt

  • @user-qg7lb1jx8b

    @user-qg7lb1jx8b

    Жыл бұрын

    4 is not prime

  • @ChrisCox-wv7oo

    @ChrisCox-wv7oo

    10 ай бұрын

    Being divisible by 4 is the same as being divisible by 2 two times... I'm not sure if Chad GPT is going to do mentally cripple an entire generation of engineers, or help them learn quicker through failure

  • @gersonsales9231
    @gersonsales9231 Жыл бұрын

    ++subscribers

  • @amalaljohari9358
    @amalaljohari9358 Жыл бұрын

    Actually that shows "Time Limit Exceeded" A better solution can be: if (n return false; while (n > 1) { if (n % 2 == 0) n /= 2; else if (n % 3 == 0) n /= 3; else if (n % 5 == 0) n /= 5; else return false; } return n ==1;

  • @NegiRohit

    @NegiRohit

    Жыл бұрын

    I came up with this exact solution without seeing this code.

Келесі