
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Longest Continuous Increasing Subsequence in C++
Suppose we have an array of integers; we have to find the length of longest continuous increasing subarray.
So, if the input is like [2,4,6,5,8], then the output will be 3. As the longest continuous increasing subsequence is [2,4,6], and its length is 3.
To solve this, we will follow these steps −
- if size of nums <= 1, then −
- return size of nums
- answer := 1, count := 1
- for initialize i := 0, when i < size of nums, update (increase i by 1), do −
- if nums[i] < nums[i + 1], then −
- (increase count by 1)
- answer := maximum of answer and count
- Otherwise
- count := 1
- if nums[i] < nums[i + 1], then −
- return answer
Let us see the following implementation to get better understanding −
Example
#include <bits/stdc++.h> using namespace std; class Solution { public: int findLengthOfLCIS(vector<int>& nums) { if (nums.size() <= 1) return nums.size(); int answer = 1, count = 1; for (int i = 0; i < nums.size() - 1; i++) { if (nums[i] < nums[i + 1]) { count++; answer = max(answer, count); } else { count = 1; } } return answer; } }; main(){ Solution ob; vector<int> v = {2,4,6,5,8}; cout << (ob.findLengthOfLCIS(v)); }
Input
{2,4,6,5,8}
Output
3
- Related Articles
- Longest Increasing Subsequence
- Longest Increasing Subsequence in Python
- Java Program for Longest Increasing Subsequence
- Number of Longest Increasing Subsequence in C++
- How to find the length of the longest continuous increasing subsequence from an array of numbers using C#?
- Program to find length of longest increasing subsequence in Python
- Program to find length of longest circular increasing subsequence in python
- C++ Program to Find the Longest Increasing Subsequence of a Given Sequence
- Longest Common Subsequence
- Longest Bitonic Subsequence
- Longest Palindromic Subsequence
- Increasing Triplet Subsequence in Python
- Longest Common Subsequence in C++
- Longest Harmonious Subsequence in C++
- Longest Palindromic Subsequence in C++

Advertisements