4 ms·
The best, IMO, version of the talk's program has a signature (as expressed in my ad hoc pseudo-typed-python): def getHasMaxAndMaxOfIntArr ( intArr :int[] ) -
by MrMcCall 2y ago
The best, IMO, version of the talk's program has a signature (as expressed in my ad hoc pseudo-typed-python):
def getHasMaxAndMaxOfIntArr ( intArr :int[] ) -> ( hasMax :bool , maxV :int ) :
where hasMax is false iff len( intArr ) == 0
and maxV is only meaningful if haxMax is true
LL is a mathematician, which is the problem here ;-)
because -Inf for the return value, for when there are no elements, is semantically different than if the array has elements and they're all -Inf.
That's why exceptional conditions must be coded as a separate piece of result data.
Things must be as simple as possible, but not simpler.