Complex Number Multiplication

Medium

Description

Given two complex numbers num1 and num2 as strings in the form "a+bi", return the product also as a string in the same form.

Examples

Input:num1 = "1+1i", num2 = "1+1i"
Output:"0+2i"
Explanation:

(1+i)*(1+i)=2i.

Input:num1 = "1+-1i", num2 = "1+-1i"
Output:"0+-2i"
Explanation:

Works with negative numbers.

Input:num1 = "2+3i", num2 = "4+-2i"
Output:14+8i
Explanation:

(2+3i)*(4-2i) = 2*4 + 2*(-2i) + 3i*4 + 3i*(-2i) = 8 - 4i + 12i - 6i² = 8 + 8i - 6(-1) = 8 + 8i + 6 = 14+8i

Constraints

  • Valid complex number format

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!