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.
Examples
01 · Example 1
nums = [5, 2, 4, 3, 1, 6] return = 3
You 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.
02 · Example 2
nums = [2, 9, 12, 13, 4, 7, 6, 5, 10] return = 4
You can split the array into: [2], [9, 4], [12, 10], [13, 7, 6, 5].
03 · Example 3
nums = [1, 1, 1] return = 3
Because of the strictly descending order you have to split it into 3 subsequences: [1], [1], [1].
Constraints
Unknown yet. If you happen to know about it, feel free to lmk! TYSM ~3~More Google problems
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Merge Intervals with NamesONSITE INTERVIEW · Seen Jun 2025
public int minSubsequences(int[] nums) {
// write your code here
}
nums[5, 2, 4, 3, 1, 6]
expected3
sign in to submit