-4

The function would basically just generate all of the ways to partition an array into n buckets while keeping the order of the original array. It would generate an array of arrays of arrays

Function signature:

func(arr, n)
arr = an array of numbers
n = int <= length(arr)

Example function calls:

func([1, 2, 3], 1) would return [ [[1, 2, 3]] ]
func([1, 2, 3], 2) would return [ [[1],[2, 3]], [[1, 2],[3]]]
func([1, 2, 3], 3) would return [ [[1], [2], [3]] ]
Vasan
  • 4,810
  • 4
  • 20
  • 39

1 Answers1

0

I was able to figure this out.

I did it by
1. implementing algorithm in this post - How to find all partitions of a set
2. filter out partitions with elements that do not maintain the order of the original array
3. filter out partitions that are not of size n