This is different from classic LIS problem. Here I want number of contigiouscontiguous longest increasing subsequences!
For Example: INPUT example: arr[] = { 3, 6, 10, 8, 11, 17, 16, 100 }
OUTPUT: 2
INPUT: arr[] = { 3, 6, 10, 8, 11, 17, 16, 100 }
OUTPUT: 2
Explanation: There are 2 longest contigiouscontiguous subsequences -> { 3, 6, 10: }{ 3, 6, 10 }
and { 8, 11, 17 }{ 8, 11, 17 }
.
Here is a function that I have made to achieve the task.But But is theirthere any optimized way instead of this brute force approach?
#define ll long long int
ll longestIncSeq(vector<ll> temp, ll n)
{
ll count=0,mymax = -1,flag=0,dummy=0;
while( (flag==0) && (!(temp.empty())) )
{
ll max = 1, len = 1, maxIndex = 0;
for (ll i=1; i<n; i++)
{
if (temp[i] > temp[i-1])
len++;
else
{
if (max < len)
{
max = len;
maxIndex = i - max;
}
len = 1;
}
}
if (max < len)
{
max = len;
maxIndex = n - max;
}
if( max == 1 )
{
return count;
}
if( (mymax == max) || (dummy==0) )
{
count++;
dummy++;
}
else
{
flag = 1;
}
temp.erase(temp.begin()+maxIndex , temp.begin()+maxIndex+max);
mymax = max;
n = temp.size();
}
return count;
}
```