Approach #1 Simple Solution[Accepted]


Multiplication of two complex numbers can be done as:

We simply split up the real and the imaginary parts of the given complex strings based on the '+' and the 'i' symbols. We store the real parts of the two strings and as and respectively and the imaginary parts as and respectively. Then, we multiply the real and the imaginary parts as required after converting the extracted parts into integers. Then, we again form the return string in the required format and return the result.

Complexity Analysis

  • Time complexity : . Here splitting takes constant time as length of the string is very small .

  • Space complexity : . Constant extra space is used.