Skip to content

Missing Test Case - 3698. Split Array With Minimum Difference #32512

@muvelus

Description

@muvelus

LeetCode Username

muvelus

Problem Number, Title, and Link

  1. Split Array With Minimum Difference, https://leetcode.com/problems/split-array-with-minimum-difference/description/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

The following testcase is not in the list of test cases:
[1,2,3,4,5,5]

Expected answer: 10

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public long splitArray(int[] A) {
        int n = A.length;
        int i=0;
        int prev=0;
        long leftSum = 0;
        long rightSum = 0;
        boolean skip = false;
        long result=0;

        while((i < n) && A[i] > prev) {
            leftSum += A[i];
            prev = A[i];
            i++;
        }

        int mid = prev;
        int midi = i-1;
        prev = Integer.MAX_VALUE;

        if((i<n) && mid == A[i]) {
            skip = true;
        }

        while((i < n) && A[i] < prev) {
            rightSum += A[i];
            prev = A[i];
            i++;
        }

        if(i != n) {
            return -1;
        }

        if(rightSum == 0) {
            result = Math.abs((long)(leftSum - mid) - (long)(rightSum + mid));
            return result;
        }

        if((leftSum - mid) == 0) {
            result = Math.abs((long)(leftSum - rightSum));
            return result;
        }

        result = Math.abs((long)(leftSum - rightSum));

        if(!skip) {
            result = Math.min(result, Math.abs((long)(leftSum - mid) - (long)(rightSum + mid)));
        }

        return result;
    }
}

Expected behavior

The following testcase is not in the list of test cases:
[1,2,3,4,5,5]

Upto index 4 it is strictly increasing and from index 5 it is strictly decreasing.
leftSum = 1 + 2 + 3 + 4 + 5
rightSum = 5

Expected answer: 10

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions