Sum of Square Numbers - Leetcode 633 - Python

  Рет қаралды 13,045

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер
@AnordinaryMan007
@AnordinaryMan007 5 ай бұрын
I think 9 should also be true as 3^2 + 0^2 is 9.
@maanas_sehgal
@maanas_sehgal 5 ай бұрын
Well it depends if we can include 0 in I j or not
@AnordinaryMan007
@AnordinaryMan007 5 ай бұрын
@@maanas_sehgal Well it is given in the constraint
@02devavratkumarmahato11
@02devavratkumarmahato11 5 ай бұрын
Buddy it's a^2 + b^2 so it can be only a and b
@02devavratkumarmahato11
@02devavratkumarmahato11 5 ай бұрын
In 3^2 and 0^2 there are three integers
@_DashingAdi_
@_DashingAdi_ 4 ай бұрын
Wtf​@@02devavratkumarmahato11
@MykolaPavluchynskyi
@MykolaPavluchynskyi 5 ай бұрын
One optimization can be also to track not only start/end but also power of start/power of end. So we don't need to recalculate power of start when we change end, or recalculate power of end when we change start. So save one multiplication on each iteration. Still constant space but saving on each iteration.
@dhaanaanjaay
@dhaanaanjaay 5 ай бұрын
I came up with similar solution but my mistake was that I initialized r with c instead of sqrt of c, which got me into TLE.
@galkk3
@galkk3 5 ай бұрын
my solution, like your first one but with O(1) SC: if c == 0: return True for a in range(ceil(sqrt(c))): b = sqrt(c - a * a) if b % floor(b) == 0: return True return False
@jersefrenzer1265
@jersefrenzer1265 4 ай бұрын
The prime divisors of the squarefree part of c must all be 1 mod 4. If c is 3 mod 4, you can automatically rule it out. 9 evaluates to true by the way since 3^2+0^2=9.
@bedokhaled9628
@bedokhaled9628 5 ай бұрын
Actually we don't really need the Hashset in the first solution, simply check if b is perfect square or not, we can check if a number is perfect square by comparing the floor and ceil of sqrt(number) : potential_b = sqrt(c - a^2) if floor(potential_b) == ceil(potential_b): return True
@asagiai4965
@asagiai4965 5 ай бұрын
I haven't seen his solution (I think it is good or ok) My solutions are either. A.) Uses some sort of Binary Search. Like starting min is 0 to max c. B.) Uses sliding window? I think there's a lot of solutions to this problem. And should be interesting.
@hoyinli7462
@hoyinli7462 5 ай бұрын
Good video! You can reverse the title of this video so the others can find this video easier
@inferno4738
@inferno4738 5 ай бұрын
Hey, how do you realize that it's gonna pass the time complexity? I saw 2^31 and that's about 10^9 So I thought it gotta be a O(1) or O(n) solution Got stuck there and didn't even think of brute force
@JamesBond-mq7pd
@JamesBond-mq7pd 5 ай бұрын
Incredible solutioN!
@joydeeprony89
@joydeeprony89 5 ай бұрын
smooth AF
@pradeepballa2712
@pradeepballa2712 5 ай бұрын
great solution
@ngneerin
@ngneerin 5 ай бұрын
def soluion(c): s = set() for a in range(int(sqrt(c))+1): sqr = a*a s.add(sqr) if c-sqr in s: return True return False
@ngneerin
@ngneerin 5 ай бұрын
Excitedly I added this solution before the video could end, thinking I outsmarted you, until I saw the last solution
@sanchitdeepsingh9663
@sanchitdeepsingh9663 5 ай бұрын
thanks
@7oeseven793
@7oeseven793 5 ай бұрын
W title
@mohanedomer9081
@mohanedomer9081 5 ай бұрын
I was waiting for this one
@zweitekonto9654
@zweitekonto9654 5 ай бұрын
The cooler 2 sum problem.
@satyamjha68
@satyamjha68 5 ай бұрын
Solved it!!
@optimistcarrot4915
@optimistcarrot4915 5 ай бұрын
Hi, why do you not make videos about the 2 hard problems they asked yesterday and the day before? Just curious
@NeetCodeIO
@NeetCodeIO 5 ай бұрын
I think i already made a video for IPO. For the second one I was out of town unfortunately
@asagiai4965
@asagiai4965 5 ай бұрын
I'm just gonna throw it out there. But If A or B is 0 then the other letter must be a perfect square. If there is no perfect square then it is false.
@chien-yuyeh9386
@chien-yuyeh9386 5 ай бұрын
🎉🎉
@Karan-gh9ki
@Karan-gh9ki 5 ай бұрын
we do not allow 2 same integers (0:39) technically for 8 it is not 2 and 2, it is 2 and -2. We are squarring the numbers so obviously there wont be a difference. And for 9 it should be true because 3^2 + 0^2 is 9
@yang5843
@yang5843 5 ай бұрын
How about for 0 then?
@whyredvince
@whyredvince 5 ай бұрын
What's up with the title?
@freecourseplatformenglish2829
@freecourseplatformenglish2829 5 ай бұрын
Dude You are complicating the solution. Below is my solution. class Solution: def judgeSquareSum(self, c: int) -> bool: for a in range(int(c ** 0.5) + 1): b = (c - a ** 2) ** 0.5 if b == int(b): return True return False
@LIGHTsoldier
@LIGHTsoldier 5 ай бұрын
I think you forgot to change the title before publishing.
@Rahul-pr1zr
@Rahul-pr1zr 5 ай бұрын
Wow, how did I miss kzbin.info/www/bejne/eGG4o3qVjZeZl6M!
Shortest Subarray with Sum at Least K - Leetcode 862 - Python
27:57
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 673 М.
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 7 МЛН
Human vs Jet Engine
00:19
MrBeast
Рет қаралды 209 МЛН
Человек паук уже не тот
00:32
Miracle
Рет қаралды 4,2 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 144 М.
Perfect Squares - Dynamic Programming - Leetcode 279 - Python
15:12
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 227 М.
Numberphile's Square-Sum Problem was solved! #SoME2
26:37
HexagonVideos
Рет қаралды 389 М.
LeetCode is a JOKE with This ONE WEIRD TRICK
4:54
AlgoMonster
Рет қаралды 88 М.
Count Number of Teams - Leetcode 1395 - Python
17:29
NeetCodeIO
Рет қаралды 13 М.
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 7 МЛН