You should sort the array first