UKG interview question

How to solve some basic coding problems.