This is a poorly written question. There's nothing in the vignette that can tell this cocaine rather than opiates withdrawal. Perhaps the only hint in the question is the preterm labor which points more to cocaine rather than heroin.
I asked a neonatologist for this and she said there's no consensus as to which clinical features really tell the difference.
She said in practice our best bet is to look at maternal risk factors. Abruptio, preterm, and polysubstance abuse are more likely to be associated with Cocaine rather than Opioids. In the question they gave two of these risk factors; preterm and multiple substances.
Although, I did look it up on e-medicine.. shortly afterwards..
It said the following:
Opiate withdrawal: Signs of NAS include hyperirritability, gastrointestinal dysfunction, respiratory distress, and vague autonomic symptoms (eg, yawning, sneezing, mottling, fever). Tremors and jittery movements, high-pitched cries, increased muscle tone, and irritability are common. Normal reflexes may be exaggerated. Loose stools are common, leading to possible electrolyte imbalances and diaper dermatitis.
Long-term symptoms have been difficult to study, but evidence supports that these children show hyperphagia, increased oral drive, sweating, hyperacusis, irregular sleep patterns, poor tolerance to environmental changes, and continued loose stools.
NAS appears to be less severe if the mother has used opiates longer than one week prior to delivery.
Cocaine: Acute signs such as tremors, high-pitched cry, irritability, excess suck, hyperalertness, apnea, and tachycardia can be seen with the first 72 hours of life. However, because these signs can be seen before the typical half-life of a dose immediately prior to delivery, one can argue that these signs are more typical of intoxication, rather than withdrawal.
But yeah, I agree, a poorly written question indeed!