Qualcomm Interview Question

Write detailed code on board to achieve certain purpose.