We study a mass transport model, where spherical particles diffusing on a ring can stochastically exchange volume $v$, with the constraint of a fixed total volume $V=sum_{i=1}^N v_i$, $N$ being the total number of particles. The particles, referred to as $p$-spheres, have a linear size that behaves as $v_i^{1/p}$ and our model thus represents a gas of polydisperse hard rods with variable diameters $v_i^{1/p}$. We show that our model admits a factorized steady state distribution which provides the size distribution that minimizes the free energy of a polydisperse hard rod system, under the constraints of fixed $N$ and $V$. Complementary approaches (explicit construction of the steady state distribution on the one hand ; density functional theory on the other hand) completely and consistently specify the behaviour of the system. A real space condensation transition is shown to take place for $p>1$: beyond a critical density a macroscopic aggregate is formed and coexists with a critical fluid phase. Our work establishes the bridge between stochastic mass transport approaches and the optimal polydispersity of hard sphere fluids studied in previous articles.