1292. Find Minimum of Two Numbers Without If

EasyBit ManipulationBit ManipulationBranchlessSign Bit

Given two integers a and b, return the smaller of the two without using any conditional branch. Derive the result from the sign of the difference using bitwise operations.

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

Output: Return the minimum of a and b.

Examples

Example 1
Input: {"a":3,"b":9}
Output: 3
Explanation: 3 is smaller, returned without a branch.
Example 2
Input: {"a":-3,"b":-9}
Output: -9
Explanation: -9 is smaller than -3.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →