LeetCode-Feedback / LeetCode-Feedback

660 stars 315 forks source link

[BUG] - Test case out of bound #23080

Closed pranjalchanda08 closed 1 week ago

pranjalchanda08 commented 1 month ago

LeetCode Username

pchanda2410

Problem Number, Title, and Link

https://leetcode.com/problems/maximum-product-subarray

Bug Category

Incorrect test case (Output of test case is incorrect as per the problem statement)

Bug Description

image As per the description the overall bound of multiplication is not out of 32 bits. But this test case fails the constrain.

Language Used for Code

C

Code used for Submit/Run operation

int maxProduct(int* nums, int numsSize) {
    if (numsSize == 0) return 0;

    int max_val = nums[0];
    int min_val = nums[0];
    int result = nums[0];

    for (int i = 1; i < numsSize; i++) {
        if (nums[i] < 0) {
            max_val ^= min_val;
            min_val ^= max_val;
            max_val ^= min_val;
        }

        max_val = fmax(nums[i], (max_val * nums[i]));
        min_val = fmin(nums[i], (min_val * nums[i]));

        result = fmax(result, max_val);
    }

    return result;
}

Expected behavior

No runtime errors.

Screenshots

image

Additional context

No response

exalate-issue-sync[bot] commented 1 month ago

Winston Tang commented: Hello pchanda2410,

Thank you for reaching out to us with your concerns. To assist you better, could you please provide us with the specific test case that you believe is inconsistent with the problem constraints? This will be really helpful in order for us to further investigate this issue.

While waiting for your response, you might also want to double-check the problem statement for any potential misunderstandings and retest your code with typical and edge cases. Especially, please verify your understanding of the 32-bit constraint you mentioned.

Looking forward to your reply.

Best regards, LeetCode Support Team

pranjalchanda08 commented 1 month ago

The same logic is working on JAVA but not in C

pranjalchanda08 commented 1 month ago

the only thing that helped is by changing the "int" to "long double"

luciphania commented 1 week ago

Hello there,

Thanks for reaching out!

While the given test case still satisfied the original constraints, the constraints have been updated such that any subarray product now fits inside 32-bit integer now.

Best, LeetCode Support Team