If Max is a power of 2 and all array elements are equal
if ( isPower2 && CheckAllEqual ( arr , N ) ) { return ( int ) ( Math . Log ( Max ) / Math . Log ( 2 ) ) ; } else { return ( int ) Math . Ceiling ( Math . Log ( Max ) / Math . Log ( 2 ) ) + 1 ; } }