Siemens interview question

What I did in the specific examples