Converting the problem as Longest Increasing Sequence thus
we could solve it by efficient algorithm with time complexity O(N log N)