Exploring the nature of exotic multiquark candidates such as the X(3872) plays a pivotal role in understanding quantum chromodynamics (QCD). Despite significant efforts, consensus on their internal structures is still lacking. As a prime example, it remains a pressing open question to decipher the X(3872) state between two popular exotic configurations: a loose hadronic molecule or a compact tetraquark. We demonstrate a novel approach to help address this problem by studying the X(3872) production in heavy ion collisions, where a hot fireball with ample light as well as charm (anti-)quarks is available for producing the exotics. Adopting a multiphase transport model (AMPT) for describing such collisions and implementing appropriate production mechanism of either molecule or tetraquark picture, we compute and compare a series of observables for X(3872) in Pb-Pb collisions at the Large Hadron Collider. We find the fireball volume plays a crucial role, leading to a 2-order-of-magnitude difference in the X(3872) yield and a markedly different centrality dependence between hadronic molecules and compact tetraquarks, thus offering a unique opportunity for distinguishing the two scenarios. We also make the first prediction of X(3872) elliptic flow coefficient to be tested by future experimental measurements.