-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
killer-whale
Problem Number, Title, and Link
- 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
It is possible to submit code that gets accepted, but fails when given this custom test case: [5,10,10,10]
Output
5
Expected
-1
Language Used for Code
Python/Python3
Code used for Submit/Run operation
class Solution:
def splitArray(self, nums: List[int]) -> int:
changes, lengths = [], []
for k, g in groupby(((a > b) - (a < b) for a, b in pairwise(nums))):
changes.append(k)
lengths.append(sum(1 for _ in g))
if any(a > b for a, b in pairwise(changes)):
return -1
if len(lengths) == 1:
return (min(abs(sum(nums[1:]) - nums[0]), abs(sum(nums[:-1]) - nums[-1]))
if changes[0] != 0 or len(nums) < 3
else -1)
midpoint = sum(lengths[:-1]) + (changes[-1] == 0)
return min(
abs(sum(nums[:midpoint]) - sum(nums[midpoint:])),
abs(sum(nums[:midpoint + 1]) - sum(nums[midpoint + 1:]))
)Expected behavior
This code should not be accepted when you submit it.
Screenshots
No response
Additional context
No response