Given a certain integer  ```n, n > 0```and a number of partitions,  ```k, k > 0```; we want to know the partition which has the maximum or minimum product of its terms.

The function ```find_spec_partition() ```, will receive three arguments,  ```n```,  ```k```, and a command:  ```'max' or 'min'```

The function should output the partition that has maximum or minimum value product (it depends on the given command) as an array with its terms in decreasing order.

Let's see some cases (Python and Ruby)
```
find_spec_partition(10, 4, 'max') == [3, 3, 2, 2]
find_spec_partition(10, 4, 'min') == [7, 1, 1, 1]
```
and Javascript:
```
findSpecPartition(10, 4, 'max') == [3, 3, 2, 2]
findSpecPartition(10, 4, 'min') == [7, 1, 1, 1]
```
The partitions of 10 with 4 terms with their products are:
```
(4, 3, 2, 1): 24
(4, 2, 2, 2): 32
(6, 2, 1, 1): 12
(3, 3, 3, 1): 27
(4, 4, 1, 1): 16
(5, 2, 2, 1): 20 
(7, 1, 1, 1): 7   <------- min. productvalue
(3, 3, 2, 2): 36  <------- max.product value
(5, 3, 1, 1): 15
```
Enjoy it!

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Mathematics

Starter code: def find_spec_partition(n, k, com):
	

Solutions:
def find_spec_partition(n, k, com):
	(x, r) = divmod(n, k)
	return {'max': [x + 1] * r + [x] * (k - r), 'min': [n + 1 - k] + [1] * (k - 1)}[com]


def find_spec_partition(n, k, com):
	return [n - k + 1] + [1] * (k - 1) if com == 'min' else [n // k + 1] * (n % k) + [n // k] * (k - n % k)


def find_spec_partition(n, k, com):
	if com == 'min':
		return [n - k + 1] + [1] * (k - 1)
	(q, r) = divmod(n, k)
	return [q + 1] * r + [q] * (k - r)


def find_spec_partition(n, k, com):
	if com == 'min':
		answer = [n]
		while len(answer) != k:
			answer[0] -= 1
			answer.append(1)
		return answer
	else:
		answer = [1 for i in range(k)]
		cur = 0
		while sum(answer) != n:
			answer[cur] += 1
			cur += 1
			if cur == k:
				cur = 0
		return answer


def find_spec_partition(n, k, com):
	if com == 'min':
		return [n - k + 1] + [1] * (k - 1)
	else:
		return [n // k + 1 if i < n % k else n // k for i in range(k)]
	return r


def find_spec_partition(n, k, com):
	part = [0] * k
	if com == 'min':
		part[1:k] = [1] * (k - 1)
		part[0] = n - k + 1
	else:
		for p in range(len(part)):
			maxPart = round(n / (k - p))
			part[p] = maxPart
			n -= maxPart
	part.sort(reverse=True)
	return part


def find_spec_partition(n, k, com):
	if com == 'min':
		return [n - k + 1] + [1] * (k - 1)
	else:
		(li, i) = ([1] * k, 0)
		while sum(li) < n:
			li[i % k] += 1
			i += 1
		return li