LeetCode-Feedback / LeetCode-Feedback

661 stars 315 forks source link

[BUG] - <3171. Find Subarray With Bitwise AND Closest to K missing testcase> #22541

Closed oh0873 closed 3 weeks ago

oh0873 commented 3 months ago

LeetCode Username

Algoh9

Problem Number, Title, and Link

  1. Find Subarray With Bitwise AND Closest to K https://leetcode.com/problems/find-subarray-with-bitwise-and-closest-to-k/

Bug Category

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

Bug Description

There's an incorrect solution that passes all test cases but.

Language Used for Code

C++

Code used for Submit/Run operation

class Solution {
public:
    int minimumDifference(vector<int>& nums, int k) {
        // nums.clear(); nums.resize(100000, 0);
        // for(int i = 0; i < 100000; i ++)
        //     nums[i] = i + 1;
        int n = nums.size();
        vector<int> v;
        for(int i = 0; i < n; i ++) {
            if(v.empty() or v.back() != nums[i])
                v.push_back(nums[i]);
        }
        int m = v.size();
        int ans = INT_MAX;
        for(int i = 0; i < m; i ++) {
            int andd = v[i];
            int cnt = 0;
            for(int j = i; j < min(m, i + 31); j ++) {
                andd &= v[j];
                cnt ++;
                ans = min(ans, abs(k - andd));
                if(andd <= k or andd == 0) break;
            }
            // cout << "-------\n";
            // cout << cnt << endl;
        }
        return ans;
    }
};

/*
nums =
[31,30,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,23]

k =
16
*/

Expected behavior

For

nums =
[31,30,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,29,27,23]

k =
16

The given code fails. However, it passes all test cases.

Screenshots

No response

Additional context

No response

luciphania commented 3 months ago

Hello,

Your reported issue has been relayed to our team for thorough investigation. We appreciate your patience as we work to address and resolve this matter. We will reach out to you when we have updates regarding the issue.

If you have any further questions or concerns in the meantime, please feel free to let us know.

Best regards, LeetCode Support Team

luciphania commented 3 weeks ago

Thank you for your time.

Your feedback has been used to enhance the problem. As a token of our appreciation, your LeetCode account has been credited with 100 LeetCoins.

If you have any more questions or additional feedback, please don't hesitate to let us know. Your continued support is invaluable to us!

Best regards, The LeetCode Team