sample test cases:
input:
10
output:
22
input:
125
output:
212
2.We are given an array and a number k .Here we need to split the given array in to k sub arrays such that each subarray consists of atleast one element in it.we can split an array in many ways but we need to split the given array in two ways so that we get minimum and maximum possible cost .we need to output the difference of this max and min values.(cost of a subarray= first lement + last element)
Example :
A=[1,3,5,1]
k=2
we have to split the given array in to two subarrays
[1,3] [5,1] this combination gives maximum cost ie (1+3)+(5+1)=10
[1] [3,5,1] this combination gives minimum cost ie (1+1)+(3+1)=6
difference->10-6=4(ans)
If there are any similar questions of this type please share theem with me