added solution for sorted list