We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all 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)