Qualcomm interview question

some basic algorithm