Skip to content

Missing Test Case - 1658. Minimum Operations to Reduce X to Zero #7721

@pandacover

Description

@pandacover

Your LeetCode username

LuvMakin

Category of the bug

  • Question
  • Solution
  • Language
  • Missing Test Cases

Description of the bug

Code you used for Submit/Run operation

// Two Sum
class Solution {
public:
    int helper (vector<int> &v, int tar, int st, int en) { 
        int ans=0, sum=0; 
        unordered_map<int, int> mp; 
        
        for (int i = st; i <= en; ++i) { 
            sum += v[i];
            if(sum == tar) ans = max(ans, i + 1);

            if(mp.count(sum - tar)) ans = max(ans, i - mp[sum - tar]); 
            
            if(!mp.count(sum)) mp[sum] = i;
        } 
        return ans;
    } 
    int minOperations (vector<int>& nums, int x) {
        int n = nums.size(); 
        int sum = 0;

        if(n == 1) return x == nums[0];
        
        for (auto &i: nums) sum += i; 
        if(sum == x) return n;

        int ans = helper(nums, sum - x, 0, n-1); 
        if(ans == 0) return -1; 
        
        return n - ans;
    }

};

Language used for code

C++

Expected behavior

-1 expected for an array with length 1 where first element of the array is not equal to the given x.
All the test case for the given condition are missing.

Example:
nums = [ 1 ]
x = 2
expected answer 0

Screenshots

All the test case have been passed
image

Example of the missing test case are under the given constraints
image

Additional context

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions