text
stringlengths
1
636
code
stringlengths
8
1.89k
In worst case it will be arr [ i - 1 ] + 1 we use all combination of a [ i - 1 ] and add 1
arr [ i ] = arr [ i - 1 ] + 1 NEW_LINE sqrNum [ i ] = 1 NEW_LINE k = 1 ; NEW_LINE
Check for all square number less or equal to i
while ( k * k <= i ) : NEW_LINE
If it gives less count then update it
if ( arr [ i ] > arr [ i - k * k ] + 1 ) : NEW_LINE INDENT arr [ i ] = arr [ i - k * k ] + 1 NEW_LINE sqrNum [ i ] = k * k NEW_LINE DEDENT k += 1 NEW_LINE
v stores optimum square number whose sum give N
while ( n > 0 ) : NEW_LINE INDENT v . append ( sqrNum [ n ] ) NEW_LINE n -= sqrNum [ n ] ; NEW_LINE DEDENT return v NEW_LINE
Driver code
n = 10 NEW_LINE
Calling function
v = minSqrNum ( n ) NEW_LINE
Printing vector
for i in range ( len ( v ) ) : NEW_LINE INDENT print ( v [ i ] , end = " " ) NEW_LINE if ( i < len ( v ) - 1 ) : NEW_LINE INDENT print ( " ▁ + ▁ " , end = " " ) NEW_LINE DEDENT DEDENT