I had a dream about a problem last night that I still haven't been able to solve. Maybe The community can give some insight.
Problem Statement.
You're given an array $$$a$$$ of size $$$n$$$, You perform the following steps in a single operation :
0) Take $$$i = 0$$$,
1) Let $$$j$$$ be the minimum index $$$(j > i)$$$ such that $$$a[j] > a[i]$$$
2) Delete the element $$$i$$$ from the array.
3) If $$$j$$$ doesn't exists, terminate the operation, else set $$$i = j$$$ and repeat from 1.
You are required to find the number of operations you can perform before the array is empty.
An $$$\mathcal{O}(n^2)$$$ algorithm is quite visible, but can you solve it in approximate linear time ?