Can you give an idea on how this question can be solved?

Like how to approach this question?

hi @isingh think in terms of sorting