DEV Community

Mohamed Shawky
Mohamed Shawky

Posted on

3 3

Mini-Max Sum Problem

Problem statement
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Solution steps:

I thought about the problem mathematically that the sum of the smallest number in a set is the minimum sum and the sum of the biggest numbers in a set is the maximum sum so:

  • Sorted the given array.

  • Get the minimum sum by the summation of the first four numbers.

  • Get the maximum sum by the summation of the last four numbers.

def miniMaxSum(arr):
    sorted_list = sorted(arr)
    min_sum = sorted_list[0] + sorted_list[1] + sorted_list[2] + sorted_list[3]
    max_sum = sorted_list[1] + sorted_list[2] + sorted_list[3] + sorted_list[4]
    print(str(min_sum) + " " + str(max_sum))
Enter fullscreen mode Exit fullscreen mode

The problem is from Hackerrank website.
The problem url: Mini-Max Sum

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post →

Top comments (1)

Collapse
 
alimalim77 profile image
Alim Mohammad

Great Work! Lets connect.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay