added greedy algo