2439. Minimize Maximum of Array (Leetcode Medium)

preview_player
Показать описание
Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!

#leetcode #coding #programming
Рекомендации по теме
Комментарии
Автор

Actually you can keep track of the ceiling of maximum average !
int sum = 0, mx = 0;
for (int i = 0; i < nums.size(); i++) {
sum += nums[i];
mx = max(mx, ((sum + i) / (i + 1));
}
return mx;

tilakmadichettitheappdeveloper
Автор

Hi Larry, I am having difficulty understanding why you have a carry. What does it help you keep track of? Also - why did you reverse the array? Was it for prefix sum concept? Thanks!

SmoothCode