ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
int maxSubarraySum(vector &arr) { int n = arr.size(); int maxSum = INT_MIN, currSum = 0; for(int i = 0; i < n; ++i){ currSum += arr[i]; maxSum = max(maxSum, currSum); if(currSum < 0) currSum = 0; } return maxSum; }
Understood the algorithm really well Sir, it's locked in my brain forever, I was able to write the code and dry run by myself just by listening to your example explanation, Thanks...please continue teaching, more success to come🤩🥳
It made my day that I was able to help 😍
int maxSubarraySum(vector &arr) {
int n = arr.size();
int maxSum = INT_MIN, currSum = 0;
for(int i = 0; i < n; ++i){
currSum += arr[i];
maxSum = max(maxSum, currSum);
if(currSum < 0) currSum = 0;
}
return maxSum;
}
Understood the algorithm really well Sir, it's locked in my brain forever, I was able to write the code and dry run by myself just by listening to your example explanation, Thanks...please continue teaching, more success to come🤩🥳
It made my day that I was able to help 😍