Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
349 B
3
Indexable
Never
//using tabulation
	public static int helper(int[] arr,int n)
	{ 
		
		
		int[] dp = new int[n];
		dp[0]=arr[0];
		dp[1]=arr[1];
		dp[2]=arr[2];
		
		
		for(int i =3; i < n;i++ )
			dp[i]=Math.min( Math.min(dp[i-1],dp[i-2] ),dp[i-3]) + arr[i] ;
		
		int answer =Math.min( Math.min(dp[n-1],dp[n-2] ),dp[n-3]) ;
		
		return answer;
	}