Find the minimum distance to reach K points.

Recently i come acrross this interseting question.The question is:
There a sorted array of points.
Initally I am a point 0.
I need to reach K points.
Find the minimum distance to reach K points.

Example
arr=[-30,-10,10,20,50]
K=3
Starting at point zero,optimaly answer will be (-10)->(10)->(20).
So the distance travelled:
abs(-10-0)+abs(-10-10)+abs(20-10)=40
I was able to solve the question with memoization ,but it failed in one test case because of stack overflow.
Can anyone help me with a Top down Approch.
Thanks in advance.

Comments (1)