Skip to content

Missing Test Case-2834. Find the Minimum Possible Sum of a Beautiful Array #21095

@Pius-Z

Description

@Pius-Z

LeetCode Username

piusz

Problem number, title, and link

2834.Find the Minimum Possible Sum of a Beautiful Array https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/description/

Category of the bug

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

Description of the bug

When solving using the formula method and $target / 2 >= n$, overflow may occur during calculation, but the existing test cases do not cover this situation, so my error code can pass without handling the overflow.

Example test case : n = 100000000, target = 1000000000.

Language used for code

Java

Code used for Submit/Run operation

class Solution {
    public int minimumPossibleSum(int n, int target) {
        long res = 0L;
        int mod = 1000_000_007;

        int split = target / 2;

        if (split >= n) {
            // Where the problem occurs
            res = (1 + n) * n / 2;
        } else {
            res = 1L * (1 + split) * split / 2 + (0L + target + target + n - split - 1) * (n - split) / 2;
        }

        return (int)(res % mod);
    }
}

Expected behavior

Example test case : n = 100000000, target = 1000000000.
This error code can pass all existing test cases, but cannot pass the above test case.

Screenshots

Additional context

https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/submissions/509114073/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions