@qkhhly Won't this fail if array has negative numbers?
According to the your logic following values are set.
dp = -2, dp = -3
Where as the correct values are below:
dp = -2, dp = -2
Please let me know if i'm missing anything here.