Only some testcases are showed correct. Can anyone help me with the issue? I have used dp with 2d array and prefix sum in each row.
Since k < n is also possible you should calculate your result like this –
int z = min(n, k);
Thanks a lot!