Pop elements from stack while stack is not empty and top of stack is smaller than arr [ i ] . We always have elements in decreasing order in a stack .
while ( s . Count != 0 && s . Peek ( ) < arr [ i ] ) s . Pop ( ) ;