Qualcomm interview question

Basic logic and coding questions.