LeetCode-Feedback / LeetCode-Feedback

667 stars 325 forks source link

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

Open shubhRepository opened 15 hours ago

shubhRepository commented 15 hours 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

exalate-issue-sync[bot] commented 15 hours ago

LeetCode Support commented: Dear academicShubh,

Thank you for reaching out with your concern about the problem “Parsing a Boolean Expression” on LeetCode. Based on our analysis, it seems there might be a misunderstanding in how the boolean expressions are expected to be evaluated. According to the problem's rules, each expression evaluates to a boolean value, either true or false, rather than an empty result.

We recommend reviewing the logical rules for AND, OR, and NOT operations as stated in the problem description. Also, make sure your implementation aligns with how nested boolean operations should be evaluated step by step. If the issue persists, try breaking down the complex boolean expression into smaller parts and test each individually to ensure they evaluate correctly.

If you have further confusion or need a deeper understanding of a specific part of the problem, consider discussing with peers in the LeetCode community or consulting additional programming resources on boolean logic evaluation.

Thank you for your continued efforts and contributions to the LeetCode community. If there are any other questions or technical issues, feel free to contact us.

LeetCode Support Team

shubhRepository commented 15 hours 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.