Interview Solution

A hacker on a roll may be able to produce–in a period of a few months–something that a small development group (say, 7-8 people) would have a hard time getting together over a year. IBM used to report that certain programmers might be as much as 100 times as productive as other workers, or more. Peter Seebach

Max Without If Else

Language Java | Level Intermediate | Category Interview Problems | July 24, 2015 4:52 pm

Comments


Interview Problem

Find the maximum of two numbers without using if-else or any comparison operator.
This algorithm gets the maximum value from two numbers without using any comparison operator and if else condition.
Example:-
Given 23 and 45. Returns 45


Output

   					 
Max value from 23 and 45 is : 45

				    

Comments

Posted by secret2006is
March 23, 2016 10:25 am

Especially for Java integers, the expression ( (c >> 31) & 0x1 ) could be simplified: (c >>> 31)



Please login to add comments.