Qualcomm interview question

Write detailed code on board to achieve certain purpose.