Thoughtworks interview question

2 porblems Long coding