Sort by

recency

|

6081 Discussions

|

  • + 0 comments
    print((sum(arr)-max(arr)), (sum(arr)-min(arr)))
    
  • + 0 comments
    print(f"{(sum(arr)-max(arr))} {(sum(arr)-min(arr))}")
    
  • + 0 comments

    Java 8 based

        public static void miniMaxSum(List<Integer> arr) {
            // Optimized implementation 
    				// Time Complexity O(n) (linear time)
    				// Space Complexity O(1)  (constant space)
    				
            long totalSum = 0;
            long minValue= Long.MAX_VALUE;
            long maxValue = Long.MIN_VALUE;
            
            for(Integer i : arr) {
                totalSum += i;
            }
            
            
            for(Integer i : arr) {
                long currentSum = totalSum - i;
                
                if(currentSum < minValue) minValue = currentSum;
                if(currentSum > maxValue) maxValue = currentSum;
            }
            
            System.out.println(minValue + " " + maxValue);
            
            // Non Optimized implementation 
    				// Time Complexity O(n *2)  (quadratic time)
    				// Space Complexity O(n) (linear space)
    				
            List<Long> sumList = new ArrayList<>();
            int tracker = 0;
            int arraySize = arr.size();
    
            while(tracker != arraySize) {
                long sum = 0;
                for(int i = 0; i < arraySize; i++) {
                    if(tracker == i) {
                        continue;
                    }
                    sum += arr.get(i);
                }
                tracker++;
                sumList.add(sum);
                sum = 0;
            }
            
            List<Long> sortedIntegers = sumList.stream()
            .sorted()
            .collect(Collectors.toList());
            System.out.println(sortedIntegers.get(0) + " " + sortedIntegers.get(sortedIntegers.size() - 1));
     }
    
  • + 0 comments

    void miniMaxSum(vector arr) { if(arr.size() == 0) return; sort(arr.begin(), arr.end()); long long int min = accumulate(arr.begin()+0, arr.begin()+4, 0); long long int max = accumulate(arr.begin()+1, arr.begin()+5, 0); cout << min << " " << max; }

    This is the approach I came with but some of the test cases are failing

  • + 0 comments

    def miniMaxSum(arr): s=0 m=0 arr.sort() for i in range(1,len(arr)): s=s+arr[i] for i in range(0,len(arr)-1): m=m+arr[i]
    print(m,s)