<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,6,7,7]
<strong>Output:</strong> [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,4,3,2,1]
<strong>Output:</strong> [[4,4]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 15</code></li>
	<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
</ul>

from collections import defaultdict

class Solution:
    def findSubsequences(self, nums: List[int]) -> List[List[int]]:
        seqs = defaultdict(dict)
        
        # Compute all pairs (first|second -> maxIndexOfPair)
        for i, firstVal in enumerate(nums[:-1]):
            for j, secondVal in enumerate(nums[i+1:]):
                key = "|".join([str(firstVal), str(secondVal)])
                if firstVal <= secondVal and key not in seqs[2]:
                    seqs[2][key] = i+j+1

        # Build on previous length up until len(nums)
        size = 2

        while size < len(nums):
            for k,v in seqs[size].items():
                last_val = int(k.split("|")[-1])

                for q in range(v+1,len(nums)):
                    val = nums[q]

                    # Add a new sequence item
                    new_key = k + f"|{val}"
                    if val >= last_val and new_key not in seqs[size+1]:
                        seqs[size+1][new_key] = q

            size += 1


        # Convert to output
        output = []
        for mapping in seqs.values():
            for key in mapping.keys():
                output.append([int(k) for k in key.split("|")])

        return output
                










25900