Pandraxicon
Pandraxicon
CC#
Created by Pandraxicon on 5/3/2023 in #help
❔ Kadane's Algorithm Help
okay I get it now thank you!!!
5 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
so Here's what I have now:
C#

public int MaxSubArray(int[] nums) {

//declarations
int globalMax = 0;
int currentMax = 0;

//validation
if(nums.Length == 1)
return nums[0];

//logic
for(int i = 0; i < nums.Length ; i++)
{
currentMax += nums[i];
globalMax = Math.Max(currentMax, globalMax);
if(currentMax < 0)
{
currentMax = 0;
}
}

return globalMax;
}
C#

public int MaxSubArray(int[] nums) {

//declarations
int globalMax = 0;
int currentMax = 0;

//validation
if(nums.Length == 1)
return nums[0];

//logic
for(int i = 0; i < nums.Length ; i++)
{
currentMax += nums[i];
globalMax = Math.Max(currentMax, globalMax);
if(currentMax < 0)
{
currentMax = 0;
}
}

return globalMax;
}
But Im getting an issue when the array is [-2, -1]
25 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
thank you! I def understand it a lot better now
25 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
kind of starting the sum over from there?
25 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
ooh I see and by doing that, it resets currentMax to be equal to the current Array[i] value in the next iteration of the for loop
25 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
what do you mean it should always start at 0?
25 replies
CC#
Created by Pandraxicon on 5/1/2023 in #help
❔ Maximum Subarray Leetcode Help
can you explain a bit about why you reset currSum to 0 if it's negative?
25 replies
CC#
Created by Pandraxicon on 4/28/2023 in #help
TwoSum Help
Is there anything else with it that you see I might need improvement on?
10 replies
CC#
Created by Pandraxicon on 4/28/2023 in #help
TwoSum Help
Im dumb
10 replies
CC#
Created by Pandraxicon on 4/28/2023 in #help
TwoSum Help
tysm
10 replies
CC#
Created by Pandraxicon on 4/28/2023 in #help
TwoSum Help
oops
10 replies
CC#
Created by Pandraxicon on 4/28/2023 in #help
TwoSum Help
oh
10 replies