Increasing Subsequences

IF
AlgoAxiomStaff Engineers
JSTS
Medium20 mins

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.

A subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.

Examples

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]]

Explanation: All non-decreasing subsequences with at least 2 elements are listed.

Example 2:

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

Output: [[4,4]]

Explanation: The only non-decreasing subsequence with at least 2 elements is [4,4].

Example 3:

Input: nums = [1,2,3]

Output: [[1,2],[1,2,3],[1,3],[2,3]]

Explanation: All possible non-decreasing subsequences with at least 2 elements.

Constraints

  • 1 <= nums.length <= 15
  • -100 <= nums[i] <= 100
Source: Subsets pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle