Google Online Assessment (OA) - Minimum Number of Decreasing Subsequence Partitions

Given an integer array, split it into strictly decreasing subarrays. Return the minimum number of decreasing subarrays you can get from splitting the array.

Examples

Example 1:

Input:

[5, 2, 4, 3, 1, 7]

Output: 3
Explanation:

The array can be split into [5, 2, 1], [4, 3], [7] to get 3 decreasing subarrays. Or it can be split into [5, 4, 3], [2, 1], [7] to also get 3 decreasing subarrays.

The partition of [5, 4, 3, 2, 1], [7] is not valid because [5, 4, 3, 2, 1] is not a subarray of the original array.

Example 2:

Input:

[2, 9, 13, 14, 4, 8, 7, 6, 10]

Output: 4
Explanation:

[2], [9, 4], [13, 10], [14, 8, 7, 6]

Example 3:

Input:

[6, 6, 6]

Output: 3
Explanation:

[6], [6], [6]

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade