LeetCode-Feedback / LeetCode-Feedback

677 stars 333 forks source link

Missing Test Case - 1106. Parsing A Boolean Expression #24842

Open shubhRepository opened 1 month ago

shubhRepository commented 1 month ago

LeetCode Username

academicShubh

Problem Number, Title, and Link

https://leetcode.com/problems/parsing-a-boolean-expression/description/?envType=daily-question&envId=2024-10-20

Bug Category

Incorrect test case (Output of test case is incorrect as per the problem statement)

Bug Description

For this test case "&(|(f)&(f,t,t))" expected output is empty.

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public boolean parseBoolExpr(String expression) {
        boolean isOpen = false;
        int expressionLen = expression.length();
        List<Boolean> res = new ArrayList<>();
        List<Boolean> currlist = new ArrayList<>();
        Stack<Character> stk = new Stack<>();
        for (int i = expressionLen - 1; i >= 0; i--) {
            char ch = expression.charAt(i);
            if (ch == ')') {
                stk.push(ch);
                isOpen = true;
            } else if (ch == '(') {
                stk.pop();
                isOpen = false;
            } else if (isOpen) {
                if (ch == 't') {
                    currlist.add(true);
                } else if (ch == 'f') {
                    currlist.add(false);
                }
            } else if (!isOpen) {
                if (currlist.size() == 0) {
                    currlist = res;
                    res = new ArrayList<>();
                }
                int currlistLen = currlist.size();
                boolean currVal = currlist.get(0);
                if (ch == '&' && currVal) {
                    for (int j = 1; j < currlistLen; j++) {
                        currVal = currVal & currlist.get(j);
                        if (!currVal) {
                            break;
                        }
                    }
                } else if (ch == '|' && !currVal) {
                    for (int j = 1; j < currlistLen; j++) {
                        currVal = currVal | currlist.get(j);
                        if (currVal) {
                            break;
                        }
                    }
                } else if (ch == '!') {
                    currVal = !currVal;
                }
                res.add(currVal);
                currlist = new ArrayList<>();
            }
        }
        return res.get(0);
    }
}

Expected behavior

It should expect result to be false.

Screenshots

image

Additional context

No response

shubhRepository commented 1 month ago

Exactly "According to the problem's rules, each expression evaluates to a boolean value, either true or false, rather than an empty result.". But the expected answer is empty.

exalate-issue-sync[bot] commented 1 month ago

LeetCode Support commented: Request #279457 "Missing Test Case - 1106. Parsin..." was closed and merged into this request. Last comment in request #279457:

Dear academicShubh,

Thank you for reaching out to LeetCode Support. We understand encountering unexpected "Wrong answer" results can be frustrating. Based on your description and the provided code, it seems the issue may arise from a logical error within your code itself. The handling of nested expressions or logical operators might not perfectly align with the expression evaluation defined in the problem statement.

We recommend revisiting the problem statement to ensure the logic in your code matches the expected evaluation process, especially how the expressions are parsed and evaluated. Utilizing the LeetCode discussion forums or checking out relevant topics can sparking ideas or providing insights from fellow LeetCode users who have tackled similar issues.

If, after these steps, you still believe there is a platform issue, please feel free to provide additional details or examples, and we will be happy to investigate further.

We appreciate your understanding and persistence.

Best regards, LeetCode Support Team

exalate-issue-sync[bot] commented 1 month ago

LeetCode Support commented: 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