Coding problem
The longest rising subsequence
The task
A fitness tracker looks for the longest streak of workouts, not necessarily on neighbouring days, in which each workout beat the one before it.
Complete LongestIncreasing(int[] values). Return the length of the longest subsequence in which every value is larger than the one before. A subsequence keeps the values in their original order but may skip any of them. An empty array gives 0. The array is never null.
Signature
public static int LongestIncreasing(int[] values)
Examples
[3, 8, 1, 9, 2, 10, 4]→4. 3, 8, 9, 10.[4, 4, 4, 4]→1. Equal values do not rise.
Limits: Up to 2,500 values; a value can be any int.
The tests check: an empty array, one value, all equal, rising and falling arrays, repeats, int.MinValue and int.MaxValue, a subsequence that skips values, and 2,500 values in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// The length of the longest strictly increasing subsequence.
public static int LongestIncreasing(int[] values)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.