Complex Number Multiplication - Problem
A complex number 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²==-1
Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplication.
Input & Output
Example 1 — Basic Multiplication
$
Input:
num1 = "1+1i", num2 = "1+1i"
›
Output:
"0+2i"
💡 Note:
Using formula (a+bi)(c+di) = (ac-bd) + (ad+bc)i: (1+1i)(1+1i) = (1×1 - 1×1) + (1×1 + 1×1)i = 0 + 2i
Example 2 — With Negative Components
$
Input:
num1 = "1+1i", num2 = "1-1i"
›
Output:
"2+0i"
💡 Note:
(1+1i)(1-1i) = (1×1 - 1×(-1)) + (1×(-1) + 1×1)i = (1+1) + (-1+1)i = 2+0i
Example 3 — Both Parts Negative
$
Input:
num1 = "1-1i", num2 = "1-1i"
›
Output:
"0-2i"
💡 Note:
(1-1i)(1-1i) = (1×1 - (-1)×(-1)) + (1×(-1) + (-1)×1)i = (1-1) + (-1-1)i = 0-2i
Constraints
- num1 and num2 are valid complex numbers in the form "a+bi" or "a-bi"
- a and b are integers in the range [-100, 100]
- The output format should match the input format
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two complex numbers as strings: "1+1i" and "1+1i"
2
Process
Parse components and apply multiplication formula
3
Output
Result as formatted string: "0+2i"
Key Takeaway
🎯 Key Insight: Complex multiplication follows the distributive property with the key rule that i² = -1
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code