Skip to content

Bug Report - Incorrect Solution Accepted for interleaving-string #5496

@priyesh761

Description

@priyesh761

Problem Link:
https://neetcode.io/problems/interleaving-string


Description

An incorrect solution for the Interleaving String problem is being accepted by the judge.


Steps to Reproduce

1️⃣ Use the following incorrect C++ solution:

class Solution {
    bool check(string& s1, string& s2, string& s3) {
        int i=0,j=0,k=0;
        while(k<s3.size()&&(i<s1.size()||j<s2.size())) {
            int tmp = k;
            while(k<s3.size()&&i<s1.size()&&s3[k]==s1[i]) {
                k++;
                i++;
            }
            if(tmp==k) return false;
            if(k==s3.size()) break;
            tmp=k;
            while(k<s3.size()&&j<s2.size()&&s3[k]==s2[j]) {
                k++;
                j++;
            }
            if(tmp==k) return false;
        }
        return i==s1.size()&&j==s2.size()&&k==s3.size();
    }
public:
    bool isInterleave(string s1, string s2, string s3) {
        bool ans = false;
        ans = ans || (s1[0]==s3[0]&&check(s1, s2, s3));
        ans = ans || (s2[0]==s3[0]&&check(s2, s1, s3));
        return ans;
    }
};

2️⃣ Use the following test case:

s1 = "aabcc"
s2 = "dbbca"
s3 = "aadbcbbcac"

Expected Output - True
Actual Output - False

  • When executed individual testcase, it correctly fails this test case.
Image
  • However, the submission is still accepted by the platform.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions