Qualcomm Interview Question

it was not that difficult.