Ice Cream Parlor

  • + 5 comments

    A simple solution O(nlongn):

    Sort the array and save 2 postions (min = 0 and max = size -1) and change this postions(min ++ and max --) until the sum is equal to M. The problem in this method is the necessity to save a copy from initial array to find the index to print them. (Memory usually is not problem in this chalange)