LeetCode-Feedback / LeetCode-Feedback

666 stars 321 forks source link

Missing Testcase - 3083 Existence of a Substring in a String and Its Reverse #21365

Closed ShaishavJogani closed 1 month ago

ShaishavJogani commented 6 months ago

LeetCode Username

shaishavjogani

Problem number, title, and link

  1. Existence of a Substring in a String and Its Reverse https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/

Category of the bug

Description of the bug

It is missing the test cases. The problem ask to find substring of size 2 which also exists in it's reverse.

It is missing testcase like this "abcdefba" where first two char and last char of string satisfies the condtion. However, I tried to submit incorrect code which basically checks for palindrome substring of size 2 or 3. It was accepted even though it is wrong.

Language used for code

JAVA

Code used for Submit/Run operation

// Paste your code here. Don't remove ``` given
// above and below the code.
class Solution {
    public boolean isSubstringPresent(String s) {
        if(s == null || s.length() < 2) {
            return false;
        }

        for(int i=0; i < s.length()-1; i++) {
            if(s.charAt(i) == s.charAt(i+1)) { // Repeating chars satisfies the conditions. Palindrom of size 2
                return true;
            }
            if((i+2) < s.length() && s.charAt(i) == s.charAt(i+2)) { // Palindrom of length 3. e.g. "aba"
                return true;
            }
        }
        return false;
    }
}

Expected behavior

Input: "abcdefgba" Expected output: true Actual output: false

Input: "abdrpdbko" Expected output: true Actual output: false

It should fail, but code got accepted.

Additional context

https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/submissions/1205974345/

LC-Pam commented 6 months ago

Hello,

Thank you for reaching out to us.

Your reported issue has been promptly relayed to our dedicated team for thorough investigation. We appreciate your patience and understanding as we work to address and resolve this matter.

Rest assured, we will reach out to you as soon as we have the results and updates regarding the issue.

Once again, thank you for your support and cooperation. If you have any further questions or concerns in the meantime, please feel free to let us know.

Best regards, LeetCode Support Team