1308. Detect if Two Integers Have Opposite Signs

EasyBit ManipulationBit ManipulationXORSign Bit

Given two integers a and b, use XOR to decide whether they have opposite signs (one strictly negative and the other non-negative). Return true if the signs differ, otherwise false. Zero counts as non-negative.

Input: A JSON object {"a": <integer>, "b": <integer>}.

Output: Return true if a and b have opposite signs, otherwise false.

Examples

Example 1
Input: {"a":3,"b":-4}
Output: true
Explanation: Different signs -> true.
Example 2
Input: {"a":3,"b":4}
Output: false
Explanation: Both non-negative -> false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →