Problem · Greedy

Decreasing Subsequences

MediumINTERNOA
See Google online assessment and hiring insights

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
drafts saved locally
public int minSubsequences(int[] nums) {
    // write your code here
}
nums[5, 2, 4, 3, 1, 6]
expected3
sign in to submit