Given a collection of numbers that may contain duplicates, find all partitions of it. (all possible ways of dividing the collection.)
For instance, the multiset {1, 1, 2} has 4 partitions:
partition 1 = { {1}, {1}, {2} } partition 2 = { {1}, {1, 2} } partition 3 = { {1, 1}, {2} } partition 4 = { {1, 1, 2} }
Here is a similar question How to find all partitions of a set but in that question, all numbers are distinct.
Definition for set partitions: https://en.wikipedia.org/wiki/Partition_of_a_set
Definition for multiset: https://en.wikipedia.org/wiki/Multiset
A solution written in any common programming language with some explanation will be greatly appreciated.
Update:
Seems like a lot of people are confused what the question is asking about. It's NOT asking for all the possible subsets of the given collection. Rather, it's asking you to find out all the different ways of dividing the given collection of numbers.