Contiguous Subarray Max

I’m trying to solve the contiguous subarray problem on CodeSignal & I came up with the following solution which is based off of Kadane’s Algorithm. My implementation passed the given test data set however upon submission, it failed. There’s no reason given on CodeSignal & I can’t look at it since I just started doing it & have less coins.

I can’t figure out why my solution is failing but the solution based on online pseudo code works, even though my solution passed the preliminary tests. I think it might have to do with integer overflow or some other reason that’s why I’ve come here to seek help from experts.

My implementation:

 public int findConsecutiveSubarray(int nums[]) {     int currentSum = 0;     int max =Integer.MIN_VALUE;;      int i=0;     while(i < nums.length) {         currentSum += nums[i];          if(max < currentSum)             max = currentSum;          if(max < nums[i]) {             max = nums[i];             currentSum = nums[i];         }          i++;     }     System.out.println("maxSum : "+ max);     return max; } 

Solution based on online:

int arrayMaxConsecutiveSum2(int[] nums) {         int currentMax = 0;         int globalMax = 0;                  globalMax = currentMax = nums[0];                  for(int i=1; i<nums.length; i++) {             currentMax = Math.max(nums[i], currentMax + nums[i]);             globalMax = Math.max(globalMax, currentMax);         }          return globalMax; }