HP Inc. interview question

most complex problem solved