q1: refractory and reduce calculation
q1: protect result header ptr when number lt header index appear gte 2 times; reorder if-else to reduce comparison