I have an array and I need all possible subarrays (segments or subsequences) with the exception of the empty one. This is not a power set, since every subarray has only elements that were contiguous in the input array.
For example, for input new int[]{1,2,3}
, the output would be:
new int[]{
new int[]{1},
new int[]{1,2},
new int[]{1,2,3},
new int[]{2},
new int[]{2,3},
new int[]{3}
}
Note that {1,3}
is not there because i don't want all subsets (the power set), just all subsequences.
I would prefer a solution using a single LINQ statement.