List Every Non-Decreasing Subsequence of a Daily Metric Series
Last updated: November 29, 2026
Quick Overview
Given a series of daily metric values, return every distinct subsequence of length at least two whose values never decrease. The input is not sorted and may contain duplicates.
0
0
0 solved
Given a series of daily metric values, return every distinct subsequence of length at least two whose values never decrease. The input is not sorted and may contain duplicates.
A Google technical screen that breaks the usual sort-then-skip dedupe trick, since sorting would destroy order. The interviewer checks that you dedupe with a per-level set instead and record results at every node of length two or more.
What the Interviewer Expects
- Explains why sorting is not allowed here
- Uses a set of values tried at each recursion level to avoid duplicate branches
- Only extends with values at least as large as the last chosen
- Records every path of length two or more, not just leaves
- States the 2^n bound
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you count these subsequences without listing them?
- How would you return only the longest ones?
- Why is a global set of tuples correct but slower?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of ints (length up to 15, values may repeat, order matters).
- Output: distinct non-decreasing subsequences of length >= 2, in any order.
- Example:
[4, 6, 7, 7]gives 8 results: `[4,6...
High-Level Design
DFS from start with the current path. Record the path whenever its length is at least 2. Then, for i from start to the end, extend with nums[i] if the path is empty or nums[i] >= path[-1].
Dedu...