Talentd
FleetCode

491. Non-decreasing Subsequences

Medium63.1% acceptance3 companies

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

Asked at 3 companies

29:42
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def findSubsequences(self, nums: List[int]) -> List[List[int]]:
3
Starter codePython 3Spaces: 4
Examples
Input
[4,6,7,7]
Input
[4,4,3,2,1]
Your code is saved on this device.Solution