Skip to content
Decoder

Non-decreasing Subsequences

Medium

Problem

Given a list of integers nums, return every different subsequence that is non-decreasing (each value is at least the one before it) and has at least two elements. A subsequence keeps the original order but may skip elements. Return them in any order.

Example 1

Input
[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
[4, 4, 3, 2, 1]
Output
[[4, 4]]

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.