Finding the min/max of consecutive numbers which equal a given sum

1.4k Views Asked by At

Given a consecutive list of numbers of size $n$, and a total sum figure $t$, what is the simplest way of finding the minimum $min$ and maximum $max$ numbers of that consecutive list?

For example,

$t = 10$

$n = 4$

$1 + 2 + 3 + 4 = 10$

$min = 1, max = 4$

Is there a way to find out the min/max for any sum value?

Updated: Added size of list condition

2

There are 2 best solutions below

0
On

Let the first number be n then the sum of four consecutive numbers are

$$n+n+1+n+2+n+3=4n+6$$

Now $$4n+6=given sum$$

Find n and n+3

the number of numbers in the list must be given so that u can add those many numbers and then equate it to the given sum then find the min and max of these numbers.

8
On

If list size = even like in your case, the minimum is $\lfloor sum/listsize\rfloor - (listsize/2-1)$ and the maximum is $\lceil sum/listsize\rceil + (listsize/2-1)$.

If list size = odd, the minimum is $ sum/listsize- (listsize-1)/2$ and the maximum is $ sum/listsize + (listsize-1)/2$.