Given a linear equation mx+n
, return n
and m
. However, the equation may be in any of the following formats:
5x+2 -> 5 2
5x-2 -> 5 -2
5x -> 5 0
-2 -> 0 -2
x -> 1 0
Here are the formats, where each ?
stands for a positive integer written without leading zeroes
?x+?
?x-?
-?x+?
-?x-?
x+?
x-?
?
-?
?x
-?x
x
All of these cases must be handled.
Specifications:
- You can assume that the equation is in one of the above formats, i.e. it matches the regex
^(-?[123456789]\d*)?x([+-][123456789]\d*)?|-?[123456789]\d*$
.
Test Cases:
-2x+3 -> -2 3
44x -> 44 0
-123 -> 0 -123
x -> 1 0
-1x -> -1 0
1 +2
be a valid output for1x+2
? \$\endgroup\$L
to the end of numbers if they get too big. Should this be allowed? \$\endgroup\$7x
is output as7 0
but7
is output as just7
? \$\endgroup\$