Above is a simple model to break down the problem into its simplest form. Of course the model can be refined. Assuming for a short flight that the ground speed doesn't change much from after takeoff to before final approach, it becomes apparent that reaching the top and descending right away gives the shortest time burning fuel (blue line) and longest time with the engines idle during descent.
Operationally you need a few minutes in cruise for ATC purposes, approach briefing, etc. So the 5 minutes mentioned by @CptReynolds in a comment makes sense.
The same model should hold true for long haul flights, only if aerospace materials and propulsion would efficiently allow a sub-orbital flight from say London to LA, but alas that's not the case.
Refining the model
* Half-climb and half-descent.
Here the flight is divided into equal time segments (maintaining the 'same ground speed' assumption). I've taken into account the shallower descent rate, and the decreasing climb rate / thrust / fuel flow the higher the jet climbs. The numbers indicate the fuel flow (FF) ratios per time-segment.
With real FF figures, further refinements can be made.
Real Boeing 737 FPPM manual (flights <500 NM)
(Click to view)
Here it is very clear that the longer the short flight (even by a little), the higher the cruise altitude. There is not a point where there is a cut-off. And from the right-hand side: the lighter the plane, the higher it should cruise.
Note regarding the cruise FF ratio being fixed at 1.25: looking at a 737 AFM, the FF doesn't change by much from FL250 to FL410 at the same weight (2374-2458 lb/hr/eng; the Mach number rises though). So, for short hops with lower cruise levels, I've maintained the cruise FF for that simple model.