Non-decreasing Subsequences

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

30:00

Non-decreasing Subsequences
medium
Free written solution
Topics
Companies

Given an integer array nums, return all the different possible non-decreasing subsequences of the 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]]
Constraints:
  • 1≤nums.length≤151 \leq nums.\text{length} \leq 15

  • −100≤nums[i]≤100-100 \leq nums[i] \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[4,6,7,7]}
4

0

6

1

7

2

7

3

path

[ ]

Grow a path from left to right. Each depth keeps its own "used" set so the same value never starts two branches at that depth.

found 0

Variables
VariableValue
path[]
depth0
found0
DepthFunction Call
Stack empty
0/35