FastPrepComplex Number Class

Complex Number Class

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Construct two integer complex numbers, add them, compare them for equality, and format them. Return [formattedSum, equality, formattedFirst, formattedSecond].

Formatting omits zero terms, writes coefficient 1 as i and -1 as -i, and uses a + bi or a - bi when both terms are nonzero.

Function

complexNumberSummary(firstReal: int, firstImaginary: int, secondReal: int, secondImaginary: int) → String[]

Examples

Example 1

firstReal = 2firstImaginary = -1secondReal = -2secondImaginary = 1return = ["0","false","2 - i","-2 + i"]

The numbers cancel under addition but are not equal.

Constraints

  • All parts fit in signed 32-bit integers and their sums do too.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] complexNumberSummary(int firstReal, int firstImaginary, int secondReal, int secondImaginary) {
  // Write your code here.
}
firstReal2
firstImaginary-1
secondReal-2
secondImaginary1
expected["0", "false", "2 - i", "-2 + i"]
Checking account…