Problem Link

Description


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

 

Example 1:

Input: nums = [4,6,7,7]
Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]

Example 2:

Input: nums = [4,4,3,2,1]
Output: [[4,4]]

 

Constraints:

  • 1 <= nums.length <= 15
  • -100 <= nums[i] <= 100

Solution


Python3

class Solution:
    def findSubsequences(self, nums: List[int]) -> List[List[int]]:
        N = len(nums)
        res = set()
 
        def go(index, curr):
            if index == N:
                if len(curr) >= 2:
                    res.add(tuple(curr))
                return
 
            go(index + 1, curr)
            if nums[index] >= curr[-1]:
                go(index + 1, curr + [nums[index]])
 
        for i in range(N):
            go(i + 1, [nums[i]])
 
        return res