Question: Alphagrep | IIT Madras | OA | 2023
1
Entering edit mode

0
Entering edit mode

first of all we have to store the unique values in an array in sorted order , as we know ,the values which are same will follow the same pattern and as no arrangements are done ,so sorting will not affect ans.

now we see that we can decrease an element only till the element before , it as then the element before can take charge and decrease futher till the element before that and we also observe that the element after will follow the same pattern , so lets say dp[i] represent different arrays formed by decreasing elements after till arr[i-1]

now dp[i]=(arr[i]-arr[i-1])*dp[i+1];

for convinience add a leading 0 in arr , and our ans will be dp[1]

 

ADD COMMENTlink 7 days ago Adarsh Maurya • 0

Login before adding your answer.

APPLY NOWSimilar Posts
Loading Similar Posts