Problem · Greedy
Decreasing Subsequences
Learn this problemProblem statement
Given an int array nums of length n. Split it into strictly decreasing subsequences.
Output the min number of subsequences you can get by splitting.
Function
minSubsequences(nums: int[]) → intExamples
Example 1
nums = [5, 2, 4, 3, 1, 6]return = 3You can split this array into: [5, 2, 1], [4, 3], [6]. And there are 3 subsequences you get.
Or you can split it into [5, 4, 3], [2, 1], [6]. Also 3 subsequences.
But [5, 4, 3, 2, 1], [6] is not legal because [5, 4, 3, 2, 1] is not a subsequence of the original array.
Example 2
nums = [2, 9, 12, 13, 4, 7, 6, 5, 10]return = 4You can split the array into: [2], [9, 4], [12, 10], [13, 7, 6, 5].
Example 3
nums = [1, 1, 1]return = 3Because of the strictly descending order you have to split it into 3 subsequences: [1], [1], [1].
Constraints
1 ≤ nums.length ≤ 2 * 10^5-10^9 ≤ nums[i] ≤ 10^9- Every input element must appear in exactly one output subsequence, and each subsequence preserves input order.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026