By using Stack and GCD|| in O(n)
Intuition\nThe Question is easy and Simple Like we Only need to find LCM,\nthe main problem is of taking care of 10 in numerator or dinomerator in the stack \n\
## Intuition\nThe Question is easy and Simple Like we Only need to find LCM,\nthe main problem is of taking care of 10 in numerator or dinomerator in the stack \n\n# Approach\nTaking example -1/2+1/2;\nTake 2 integer a & b; \n a=-1 b=2;\nNow in the stack take again 2 integer c & d;\n c=1 d=2;\n\nNow next thing is to find LCM & gcd\n             a=a*d+c*b;\n             b=b*d;\n             int gcd=__gcd(abs(a),b);\n             a=a/gcd;\n             b=b/gcd;\nAnd the final result we will store in a & b and continuing the same..... \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string fractionAddition(string exp) {\n        int x=0;\n        string s1="";\n        if(exp[0]==\'-\')\n        x=1;\n        int y=0;\n        int a=0;\n        if(x==0)\n         a=exp[x]-\'0\';\n        else\n         a=-(exp[x]-\'0\');\n        if(exp[x+1]>=\'0\' && exp[x+1]<=\'9\') //to check if a is 10 or -10  in the first numerator \n        {\n          if(x==0)\n          a=10;\n          else\n          a=-10;\n          y++;\n        }\n        int b=exp[x+2+y]-\'0\';\n        if(exp[x+3+y]>=\'0\' && exp[x+3+y]<=\'9\') ////to check if a is 10 or -10  in the first dinomerator\n        {\n          b=10;\n          y++;\n        }                         \n        stack<string>st;\n        string s=exp.substr(x+3+y,exp.size()); // pushing into stack like taking example -1/10+1/2; for we r pushing from +1/2\n        reverse(s.begin(),s.end());\n        for(int i=0;i<s.size();i++)\n        {\n            string str="";\n            str+=s[i];\n            st.push(str);\n        }\n        int c=0;\n        int d=0;\n        int i=0;\n        int nume=0,dino=0; //for checking if not 10\n        bool flag=false;   //to store "+" or "-"\n        bool check=false; //helps in calculating d if c has already been calculated \n        while(!st.empty())\n        {\n         if(st.top()=="-")\n           flag=true;\n            \n         if(st.top()>="0" && st.top()<="9" && check==false)\n         {\n           if(flag)\n           c=-(stoi(st.top()));\n           else\n           c=stoi(st.top());\n           if(nume==1)\n           {\n               if(flag)\n               c=-10;\n               else\n               c=10;\n           }\n           nume++;\n         }\n         if(st.top()>="0" && st.top()<="9" && check==true)\n         {\n           d=stoi(st.top());\n           if(dino==1)\n           {\n               d=10;\n           }\n           dino++;\n         }\n         if(st.top()=="/")\n         check=true;\n         st.pop();\n         if((st.size()==0 || st.top()=="+" ||st.top()=="-") && check)\n         {\n             cout<<a<<"/"<<b<<endl;\n             cout<<c<<"/"<<d<<endl;\n             a=a*d+c*b;\n             b=b*d;\n             int gcd=__gcd(abs(a),b);\n             a=a/gcd;\n             b=b/gcd;\n             i=0;\n             flag=false;\n             check=false;\n             c=0;\n             d=0;\n             nume=0;\n             dino=0;\n         }\n         \n         \n        }\n        return to_string(a)+"/"+to_string(b);\n    }\n};\n```
['Stack', 'C++']