Thanks all, this is a real world application. Some kind of scooter that came with 3 batteries in series. There is only room to rack 2 more.
Is the installation in Ken's picture safe?
It would be safe for temporary or short term use at limited power levels, but potentialy unsafe for regular use.
On discharge, the single 12 volt battery would run down first, and might well become reverse charged which is most undesireable.
On charge, the single 12 volt battery would be liable to overcharge and damage.
36 volts suggests not an engine starter battery, but a small electric vehicle.
6 volt batteries might be an option since these normally have a greater capacity than 12 volt ones. Use 6 in series for 36 volts, if space permits.
8 volt "golf cart" batteries are available, and you might be able to use 5 of these in series for 40 volts.
That might overstress the electrical system designed for 36 volts, but it is a small difference and would probably be fine in practice.
Remember that the charger will need replacing with one for 40 volts, which is not a common voltage.
Batteries in series should be the same type, age, capacity, make, and preferably voltage.
Any odd batteries that are to hand may be used for brief tests or expeiments, but for regular reliable service all batteries in a bank should be identical.