GeeksforGeeks Problem of the Day
Raj Gupta23 Jun 2026
#GeeksforGeeks#GFG POTD#GFG Problem of the Day#GeeksforGeeks POTD Solution
It is recommended to first try at your own. 23 June 2026
The GeeksforGeeks POTD solution is given below:
class Solution {
public:
int maxPeopleDefeated(int p) {
// Code Here
int low=1;
int high=sqrt(p);
int ans=-1;
while(low<=high){
long long mid = low + (high - low) / 2;
long long val=mid*(mid+1)*(2*mid+1)/6;
if(val>p){
high=mid-1;
}else{
ans=mid;
low=mid+1;
}
}
return ans;
}
};