Given an array, I would like to split it into two non-empty subarrays.
For example, given the following array:
val nums = Array(1, 2, 3, 4)
I would like to generate the following unique permutations:
(Array(1), Array(2, 3, 4))
(Array(2), Array(1, 3, 4))
(Array(1, 2), Array(3, 4))
(Array(3), Array(1, 2, 4))
(Array(1, 3), Array(2, 4))
(Array(2, 3), Array(1, 4))
(Array(1, 2, 3), Array(4))
The permutations are unique in the sense that if a given split is just a mirror of another split, I only need to keep one of them. Also, the order of elements in the subarrays do not matter.
See below for a working solution: https://stackoverflow.com/a/57262577/5767875. But I believe a more elegant and functional solution exists.