934. Add Two Fractions

You are given two fractions as strings in the form "a/b" and "c/d" where a, b, c, and d are positive integers and b ≠ 0, d ≠ 0.

Your task is to add the two fractions and return their sum in the simplest form as a string "x/y".

Example 1:

Input: frac1 = "3/4", frac2 = "1/7"

Output: "25/28"

Explanation: 3/4 + 1/7 = (3×7 + 1×4)/(4×7) = 25/28

Example 2:

Input: frac1 = "5/2", frac2 = "1/2"

Output: "3/1"

Explanation: 5/2 + 1/2 = 6/2 = 3/1

Now Your Turn!

Pick the correct output for the given input

Input: frac1 = "1/3", frac2 = "1/6"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • The inputs frac1 and frac2 are valid strings in the form "a/b" where 1 ≤ a, b ≤ 104
  • The final answer must be fully simplified
0
class Solution {
public:
string addFractions(string frac1, string frac2) {
// Your code goes here
}
};
Test Case

Input:

Frac1
Frac2