Skip to main content
LeetCode 537, Medium. Topics: Math, String, Simulation. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

A <a href=“https://en.wikipedia.org/wiki/Complex_number” target=“_blank”>complex number</a> can be represented as a string on 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 <em>a string of the complex number that represents their multiplication</em>.

Examples

Constraints

  • num1 and num2 are valid complex numbers.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026