The given solution approach is not clear and may be misleading


#1

Try for test case ‘1 2 4 5 3’, a small improvement in the solution will do.