1278. Check if Two Numbers Have Opposite Signs

EasyBit ManipulationBit ManipulationSign BitXOR

Given two integers a and b, determine whether they have opposite signs (one strictly negative and the other non-negative) without using comparison branches. Return true if their signs differ, otherwise false. Zero is treated 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: 3 and -4 have different signs -> true.
Example 2
Input: {"a":3,"b":4}
Output: false
Explanation: 3 and 4 are both positive -> false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →