Count All Maximum-Length Strictly Increasing Subsequences

Quick Overview

Count All Maximum-Length Strictly Increasing Subsequences. Return the number of longest strictly increasing subsequences in nums.

Count All Maximum-Length Strictly Increasing Subsequences

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the number of longest strictly increasing subsequences in nums. Subsequences preserve index order but need not be contiguous. Different index selections count separately, even when they produce the same values. The final answer fits signed 32-bit int. ```cpp class Solution { public: int findNumberOfLIS(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [1,2,2,3] Output: 2 Explanation: Either occurrence of 2 gives a length-three subsequence. ``` **Example 2:** ```text nums = [3,1,2] Output: 1 Explanation: The only length-two increasing subsequence uses 1 then 2. ``` ### Constraints - Input size: 1..2000. Values range from -1000000 through 1000000. The final count fits signed 32-bit int. ### Clarifying Questions Count index-distinct subsequences, require strict inequality and combine equal-best predecessor counts. ```hint Read the boundary condition What information besides length is needed when two predecessors yield equally long extensions? ``` ### Contract considerations Count index-distinct subsequences, require strict inequality and combine equal-best predecessor counts.

Overview: Count All Maximum-Length Strictly Increasing Subsequences. Return the number of longest strictly increasing subsequences in nums.

Google logo
Google
Jul 3, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the number of longest strictly increasing subsequences in nums. Subsequences preserve index order but need not be contiguous. Different index selections count separately, even when they produce the same values. The final answer fits signed 32-bit int.

class Solution {
public:
    int findNumberOfLIS(vector<int>& nums);
};

Examples

Example 1:

nums = [1,2,2,3]
Output: 2
Explanation: Either occurrence of 2 gives a length-three subsequence.

Example 2:

nums = [3,1,2]
Output: 1
Explanation: The only length-two increasing subsequence uses 1 then 2.

Constraints

  • Input size: 1..2000. Values range from -1000000 through 1000000. The final count fits signed 32-bit int.

Clarifying Questions Guidance

Count index-distinct subsequences, require strict inequality and combine equal-best predecessor counts.

Contract considerations

Count index-distinct subsequences, require strict inequality and combine equal-best predecessor counts.