Non-decreasing Subsequences

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
Inputnums = [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]]
These are all distinct subsequences of length at least two whose values are non-decreasing.
Example 2
Inputnums = [4,4,3,2,1]
Output[[4,4]]
The only non-decreasing subsequence of length at least two is formed by the two 4s.

Constraints

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

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate