Qualcomm Interview Question

some basic algorithm