Skip to content

Missing Test Case - 673. Number of Longest Increasing Subsequence #25021

@riyal-rj

Description

@riyal-rj

LeetCode Username

riyal-rj

Problem Number, Title, and Link

Number of Longest Increasing Subsequence : https://leetcode.com/problems/number-of-longest-increasing-subsequence/

Bug Category

Problem examples

Bug Description

Adding an extra test case for better understanding....
input=[1,5,4,3,2,6,7,10,8,9]

There is no bugs in the question or test cases...

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public int findNumberOfLIS(int[] nums) {
        int []dp=new int[nums.length];
		Arrays.fill(dp, 1);
		int n=nums.length;
		int []countLIS=new int[nums.length];
		Arrays.fill(countLIS,1);
		int maxi=-(int)9e9;
		for(int curr_ind=0;curr_ind<nums.length;curr_ind++)
		{
			for(int prev_ind=0;prev_ind<curr_ind;prev_ind++)
			{
				if(nums[curr_ind]>nums[prev_ind]  &&
						1+dp[prev_ind]>dp[curr_ind])
					{
						dp[curr_ind]=1+dp[prev_ind];
						countLIS[curr_ind]=countLIS[prev_ind];
					}
				else if(nums[curr_ind]>nums[prev_ind]  &&
						(dp[prev_ind]+1 == dp[curr_ind]))
					{
						countLIS[curr_ind]=countLIS[curr_ind]+countLIS[prev_ind];
					}				
			}
			if(dp[curr_ind]>maxi)
			{
				maxi=dp[curr_ind];
			}
		}
		int nos=0;
		for(int i=0;i<n;i++)
		{
			if(maxi==dp[i])
				nos+=countLIS[i];
		}	
		
		return nos;
    }
}

Expected behavior

input or test case 3=[1,5,4,3,2,6,7,10,8,9]
Expected Output : 4
Got the Output: 4

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions