there are times that i wonder if im being punished for skipping all my math classes during undergrad
@NeetCode2 жыл бұрын
I feel the same sometimes lol
@user-us7rg4cd6p3 ай бұрын
There are times I wonder if I am being punished for not studying Computer Science Major but trying to be a software programmer.. lol
@jideabdqudus3 жыл бұрын
My Favorite YT chanel, don't ask me why
@ambujhakhu75313 жыл бұрын
why
@playonce41862 жыл бұрын
@@ambujhakhu7531 dont worry why he said
@shavvasatya7131 Жыл бұрын
But how
@harshaggarwal19672 жыл бұрын
You just made it quick and easy.. Thanks!!
@NeetCode2 жыл бұрын
Glad it helped!
@swatiaga85542 жыл бұрын
you can also add one more condition at while loop that n!= 0 otherwise the loop will be infinite.
@sudluee3 жыл бұрын
i think the worse case time complexity is O(log(2)n) that's if n is only divisible by 2.
@fsteve64433 жыл бұрын
the GOAT uploaded
@BB8_CA3 жыл бұрын
As aways!
@littlecatboybuddy Жыл бұрын
I watch entire videos! Because I'm a beginner so the coding section is really helpful! Thank you for the great explanation :)
@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
@spaceface22882 жыл бұрын
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
@sahanar48052 жыл бұрын
+1
@harshaggarwal19672 жыл бұрын
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..
@amalaljohari9358 Жыл бұрын
Actually that shows "Time Limit Exceeded" A better solution can be: if (n < 0) 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 Жыл бұрын
I came up with this exact solution without seeing this code.
@Gerald-iz7mv Жыл бұрын
hi - is there a leetcode playlist for this as well?
@maamounhajnajeeb209 Жыл бұрын
Thanks
@_tan2112 Жыл бұрын
Helpfull
@Rishabhsingh-ev7ii2 жыл бұрын
i think u r from mars ur every video is educative
@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 Жыл бұрын
4 is not prime
@ChrisCox-wv7oo11 ай бұрын
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