ABC interview question

Solve Hackerrank problem in 5 minutes