LeetCode-Feedback / LeetCode-Feedback

662 stars 315 forks source link

[BUG] - <title> #23651

Closed Dhruvin3103 closed 2 weeks ago

Dhruvin3103 commented 3 weeks ago

LeetCode Username

Dhruvin3103

Problem Number, Title, and Link

592., Fraction Addition and Subtraction, https://leetcode.com/problems/fraction-addition-and-subtraction/

Bug Category

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

Bug Description

the question doesn't provide proper constraint for how can the "expresssion" can be, for example one test case can be as : "1/2+1/3" this is a valid test case but the question let go pass test case having expression : "-1/-2+1/3" for this the expected output cant be seen also solution gives right answer but it shows wrong answer

Language Used for Code

C++

Code used for Submit/Run operation

class Solution {
public:
    pair<int,int> solve(int a, int b, int c, int d){
        int x = a*d + b*c;
        int y = d*b;
        int z = gcd(x,y);
        return {x/z,y/z};
    }
    string fractionAddition(string s) {
        string res;
        stack<pair<int,int>> stk;
        int i=0;
        int n = s.size();
        while(i<n and (s[i]!='-' or s[i]!='+')){
            int num=0; 
            if(s[i]=='-'){
                num = -1;
            }
            else{num = 1;}
            if(stk.empty() and isdigit(s[i])){i-=1;}
            i+=1;
            int j = i;
            while(j<n and (isdigit(s[j]))){j++;}
            num *= stoi(s.substr(i,j));
            i = j+1;
            int num1 = 0;
            while(i<n and (isdigit(s[i]))){
                i+=1;
            }
            num1 = stoi(s.substr(j+1,i));
            stk.push({num,num1});
        }
        while(!stk.empty()){
            int a = stk.top().first, b = stk.top().second;stk.pop();
            if(stk.empty()){
                res = to_string(a)+"/"+to_string(b);
                break;
            }
            int c = stk.top().first, d = stk.top().second;stk.pop();
            stk.push(solve(a,b,c,d));
        }
        return res;
    }
};

Expected behavior

the test case should be given as invalid , and if the question wants the to be valid then it should be provided in description and accordingly the code can be made

Screenshots

image

ok in the image as u can see for test case 5 the expression is : "-1/-2+1/3" now for this correct output can be 5/6 if the expression is considered as valid but it seems the question cant give any expected answer i guess this is what the issue is

Also i am not sure about whether it is issue or not, if its not a issue and i am doing something wrong please let me know : )

Additional context

No response

exalate-issue-sync[bot] commented 3 weeks ago

LeetCode Support commented: Dear Dhruvin3103,

Thank you for reaching out and providing detailed information regarding your concern with Problem 592: Fraction Addition and Subtraction. Based on the problem statement and given constraints, fractions are traditionally represented with positive denominators, an implicit standard often followed across various mathematical contexts.

It appears the issue might stem from interpreting the expression "-1/-2" as valid. Typically, expressions with negative denominators aren't utilized, aligning with how fractions are conventionally reduced to avoid negative denominators, effectively representing the segment "-1/2" in this context.

You can revisit the constraints and examples provided in the question's description for clarity on valid expressions. This routine can be particularly insightful if you're constructing specialized or borderline test cases. If your current solution produces correct outputs for denominators that align with the constraints, you're likely on the right track.

If confusion persists or any other concerns arise, please don't hesitate to consult the problem discussion forums or any educational content related to fraction operations and how different platforms might interpret specific cases.

Thank you for your understanding and cooperation.

LeetCode Support Team

Dhruvin3103 commented 3 weeks ago

ok got it but isn't that a issue ? as whenever we code a problem we often explore other test case(mostly for TLE and edge case) and if user test case don't fall under the proper description or constraints it should tell the constraints as it is done with other problem, in this way user get to know their right path but here i got bit confused for a time and couldn't find out what problem constraints so if possible can u fix that so that if a user enters invalid test case it should be given error and not letting go pass the test case

exalate-issue-sync[bot] commented 2 weeks ago

Epiphania_Ekenimoh 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

exalate-issue-sync[bot] commented 2 weeks ago

Epiphania_Ekenimoh commented: Hi there,

Thank you for taking the time to share your feedback with us.

After careful consideration, we have decided not to move forward with the changes suggested in your feedback at this time due to the fact that it has been resolved already.

Please know that your input is important to us. Your continued feedback is greatly appreciated as we work towards improving our platform.

Best regards, LeetCode Support Team