Complex Number Multiplication

Problem Statement

Given two complex numbers a + bi and c + di, return their multiplication result in the form (a*c - b*d) + (a*d + b*c)i.

Example: Input: "1+2i", "3+4i" → Output: "(-5+10i)"

Approach 1: Direct Multiplication

Explanation: Split the strings to extract real and imaginary parts, then apply the formula.

Time Complexity: O(1)

Space Complexity: O(1)

    parse a and b from first number
    parse c and d from second number
    real = a*c - b*d
    imag = a*d + b*c
    return real + " + " + imag + "i"
      

Approach 2: Using Built-in Complex Number Type

Explanation: Use your language’s built-in complex number type for multiplication.

Time Complexity: O(1)

Space Complexity: O(1)

    num1 = convert input1 to complex type
    num2 = convert input2 to complex type
    result = num1 * num2
    return result as string
      
Solve on LeetCode