You just have to find the subarray with largest sum divisable by k

```
#include <bits/stdc++.h>
long long helper(vector<int> &arr, int k) {
vector<long long>prefix(arr.size());
for(int i=0;i<arr.size();i++) {
prefix[i]=(i>0?arr[i]+prefix[i-1]:arr[i]);
}
unordered_map<int,int>m;
m[0]=-1;
long long sum=0,ans=0;
for(int i=0;i<arr.size();i++) {
sum+=arr[i];
int rem=(sum%k);
if(m.find(rem)==m.end()) {
m[rem]=i;
}
else {
int start=m[rem]+1;
long long currSum=prefix[i]-(start>0?prefix[start-1]:0);
ans=max(ans,currSum/k);
}
}
return ans;
}
void numberOfChocolates(vector<int> &arr, int n, int k) {
long long ans=helper(arr,k);
cout<<ans<<endl;
}
```