Very commonly asked question, how to find least sequence count, one can try this with 2 for loops also. I did it with recursive program…
using System;
public class CandidateCode{
//get Input array of integer type from Console/UI window
public static int longestSeq(int[] input1)
{
int Count = input1.Length;
int[] input1new = new int[Count];
for (int i = 0; i < Count; i++)
{
input1new[i] = input1[i];
}
return CandidateCode.longestSeq(input1new, input1new[0], 1, 1);
}
public static int longestSeq(int[] input1, int max, int item, int count)
{
if (item == input1.Length)
{
return count;
}
int length1 = longestSeq(input1, max, item + 1, count);
int length2 = 0;
if (input1[item] > max)
{
length2 = longestSeq(input1, input1[item], item + 1, count + 1);
}
return MaxValue(length1, length2);
}
static int MaxValue(int aVal, int a1Val)
{
if (aVal > a1Val)
return aVal;
else
return a1Val;
}
}