Mid From PDF Coding C# Coding Interview

Longest Increasing Subsequence (LIS) int LIS(int[] nums) { int n = nums.Length; int[] dp = new int[n];?

rray.Fill(dp, 1);

int maxLen = 1;
for (int i = 1; i < n; i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
dp[i] = Math.Max(dp[i], dp[j] + 1);
}
maxLen = Math.Max(maxLen, dp[i]);
}
return maxLen;
}

Explanation:

For each element, find LIS ending there by checking previous smaller elements.

Follow on:

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details