- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the length of the longest continuous increasing subsequence from an array of numbers using C#?
LongestIncreaingSubsequence returns integer of the continuous subsequence from the array. The method has a for loop, which iterates and keeps the track of the numbers. the final result will have the Max calculated. Time complexity is O(N) because every element is visited once and the space complexity is O(1) because we are not making use of any storage space.
Time complexity − O(N)
Space complexity − O(1)
Example − {2,4,6,5,8}
Output − 3
Example
public class Arrays{ public int longestIncreaingSubsequence(int[] nums){ if (nums == null || nums.Length == 0){ return -1; } int res = 0, count = 0; for (int i = 0; i < nums.Count(); i++){ if (i == 0 || nums[i] > nums[i - 1]){ count++; res = Math.Max(res, count); } else{ count = 1; } } return res; } } static void Main(string[] args){ int[] nums = { 1, 3, 5, 4, 7 }; Console.WriteLine(s.longestIncreaingSubsequence(nums)); }
Output
3
- Related Articles
- Longest Continuous Increasing Subsequence in 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
- Number of Longest Increasing Subsequence in C++
- Program to find out the length of longest palindromic subsequence using Python
- Longest Increasing Subsequence
- Program to find length of longest sign alternating subsequence from a list of numbers in Python
- Program to find length of longest bitonic subsequence in C++
- Program to find length of longest common subsequence in C++
- Program to find length of longest increasing subsequence with at least k odd values in Python
- Length of Longest Fibonacci Subsequence in C++
- Longest Increasing Subsequence in Python
- Program to find length of longest balanced subsequence in Python
- Program to find length of longest anagram subsequence in Python

Advertisements