Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Test Case - 918. Maximum Sum Circular Subarray #3711

Closed
1 of 4 tasks
kanchi2438 opened this issue Jun 2, 2021 · 2 comments
Closed
1 of 4 tasks

Missing Test Case - 918. Maximum Sum Circular Subarray #3711

kanchi2438 opened this issue Jun 2, 2021 · 2 comments

Comments

@kanchi2438
Copy link

LeetCode username

kanchi2438

Category of the bug

  • Question
  • Solution
  • Language
  • Missing Test Cases

Description of the bug

There's a missing test case in problem 918
The below code got submitted successfully but should fail for the following scenario
nums[]=[8,-15,-29,-19]
Expected Output = 8

Code you used for Submit/Run operation

//Maximum Sum Circular Subarray
class Solution {
public:
    int normalMaxSubarraySum(vector<int> nums)
    {
        int i,m,res,n,x,sum;
        n=nums.size();
        m=nums[0];
        res=INT_MIN;
        
        for(i=1;i<n;++i)
        {
            
            if(nums[i]<=nums[i]+m) 
            {
                m=nums[i]+m;
            }
                
            else
            {
                m=nums[i];
            }
    
            res=max(m,res);
        }
        return res;
    }
    
    int normalMinSubarraySum(vector<int> nums)
    {
        int i,m,res,n,x,sum;
        n=nums.size();
        m=nums[0];
        res=INT_MAX;
        
        for(i=1;i<n;++i)
        {
            
            if(nums[i]>=nums[i]+m)
                {
                    m=nums[i]+m;
                }
            else
                {
                    m=nums[i];
                }
    
            res=min(m,res);
        }
        return res;
    }
    
    int maxSubarraySumCircular(vector<int>& nums) {
        int i,n,x,sum=0,ans1,ans2;
        n=nums.size();
        if(n==1)
            return nums[0];
        ans1=normalMaxSubarraySum(nums);
        ans2=normalMinSubarraySum(nums);
        
        for(i=0;i<n;++i)
        {
            sum+=nums[i];
        }
        // cout<<ans1<<" "<<ans2<<" "<<sum;
        if(ans1<0)        return ans1;
        else              return max(ans1,sum-ans2);
            
          
    }
};

Language used for code : C++

Expected behavior

The above code must not be submitted as it says the wrong answer with nums[]=[8,-15,-29,-19]
But it gets submitted successfully as there's a missing test case.

Screenshots

bug

Additional context

Kindly add the following test case
nums[]=[8,-15,-29,-19]
Expected answer = 8

@lc-kay
Copy link

lc-kay commented Jun 2, 2021

Hi @kanchi2438
Thank you for reaching out to us. I've relayed this issue to our team to investigate.

@lc-kay
Copy link

lc-kay commented Jun 3, 2021

Hi @kanchi2438
Thank you for your time. We've used your feedback to update the problem. Your LeetCode account has received 100 LeetCoins as the reward for this feedback. We appreciate your support!

@lc-kay lc-kay closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants