Dialpad interview question

Problem regarding a decision tree kind of algorithm.