good way to reduce time compelxity as the stock III question