sol by sorting
add test cases