Complex Number Multiplication

A complex number can be represented as a string in the form "real+imaginaryi", where:

  • real is the real part and is an integer in the range [-100, 100].
  • imaginary is the imaginary part and is an integer in the range [-100, 100].
  • i^2 == -1.

Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplication.

Example 1
Inputnum1 = "1+1i", num2 = "1+1i"
Output"0+2i"
(1 + i) * (1 + i) = 1 + i^2 + 2 * i = 2i, so it must be converted to the form 0+2i.
Example 2
Inputnum1 = "1+-1i", num2 = "1+-1i"
Output"0+-2i"
(1 - i) * (1 - i) = 1 + i^2 - 2 * i = -2i, so it must be converted to the form 0+-2i.

Constraints

  • num1 and num2 are valid complex numbers.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate