for input 5,4,3,2,1,-1 with k = 5 how will our DP array be initialized …??
Base case condition not clear
for the first k elements the dp array would be initialised to arr[i] itself
and max1 max2 would be calculated in the given range
watch out for the code here:
if for the first k elements dp array would be same as arr[i] then there can be cases when both max1 and max2 are on invalid index’s (i.e | i-j | %k == 0
why? can u state some example of why u say so
the above code passes all test case
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.