Code for Greedy