My solutions for google foobar
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

32 lines
1016 B

#I might over-comment those solutions since it might be
#reviewed one day, so bear with me, reviewers!
"""
Gets the biggest square below or equal to max_number
I'm sure it can be optimized but as we never get over 1M
it should be largely fast enough for most cpus:
➜ /tmp time python2 tmp.py
[1000000]
python2 tmp.py 0.01s user 0.00s system 96% cpu 0.009 total
The code is also more readable this way
"""
def get_biggest_square(max_number):
n=1
while(n*n < max_number+1):
n=n+1
return n-1
#Check readme.txt for an explaination of what this does.
# "Heavy" computation is done in get_biggest_square
def answer(area):
#check readme.txt
if(area > 1000000 or area < 1):
raise ValueError('Area is outside of bounds')
array=[]
#no need to sort or do fancy pant stuff, we go from biggest to smallest in
#a natural fashion this way
while(area != 0):
res=get_biggest_square(area)
array.append(res*res)
area-=res*res
return array