shashin Is this the right way to solve it

$T(n)=T\left ( n-1 \right ) + n^2$

$T\left ( n \right ) = T\left (n-2 \right ) + \left ( n-2 \right )^2 + n^2$

$= T\left (n-3 \right ) + \left ( n-2 \right )^2 +\left ( n-1 \right )^2 + n^2$

and in general we will have

$T\left ( n \right )= T\left (n-k \right ) + \left ( n-k+1 \right )^2 +\left ( n-k+2 \right )^2 +....................\left ( n-1 \right )^2 + n^2.$

Now if we have k = n then ,

$T\left ( n \right )= T\left (0 \right ) + \left ( 1 \right )^2 +\left ( 2 \right )^2 +....................\left ( n-1 \right )^2 + n^2.$

$T\left ( n \right )= n(n+)(n+2)/6$

Solving this we get

$T(n)= O(n^3)$