• + 1 comment

    Yes Rahul, it comes with practice. Solve questions on you own even though you write lengthy code and then check other's solutions. Thats how you will get ideas to solve efficiently. This is called Machine Learning :P

    Here is my code in Python2. I just sorted the list and printed the sum. First four elements would give least sum and last four elements would give max sum:

    def miniMaxSum(arr):
        arr = sorted(arr)
        print sum(arr[:4]), sum(arr[1:])