Deutsche Bank interview question

Understanding of the logic building for the coding