Print all maximal increasing contiguous sub-array in an array Last Updated : 26 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given an array arr[], the task is to find all the maximal contiguous increasing subarray in a given array. Examples: Input: arr[] = { 80, 50, 60, 70, 40, 50, 80, 70 } Output: 80 50 60 70 40 50 80 70 Input: arr[] = { 10, 20, 23, 12, 5, 4, 61, 67, 87, 9 } Output: 10 20 23 12 5 4 61 67 87 9 Approach: Iterate over the array and compare every element with its next neighboring element such that, if it is less than the next element, print it, else print it individually on the next line.Below is the implementation of the above approach. C++ // C++ Implementation to print all the // Maximal Increasing Sub-array of array #include <bits/stdc++.h> using namespace std; // Function to print each of maximal // contiguous increasing subarray void printmaxSubseq(int arr[], int n) { int i; // Loop to iterate through the array and print // the maximal contiguous increasing subarray. for (i = 0; i < n; i++) { // Condition to check whether the element at i, is // greater than its next neighbouring element or not. if (arr[i] < arr[i + 1]) cout << arr[i] << " "; else cout << arr[i] << "\n"; } } // Driver function int main() { int arr[] = { 9, 8, 11, 13, 10, 15, 14, 16, 20, 5 }; int n = sizeof(arr) / sizeof(arr[0]); printmaxSubseq(arr, n); return 0; } Java // Java Implementation to print all the // Maximal Increasing Sub-array of array import java.util.*; class GFG { // Function to print each of maximal // contiguous increasing subarray static void printmaxSubseq(int arr[], int n) { int i; // Loop to iterate through the array and print // the maximal contiguous increasing subarray. for (i = 0; i < n ; i++) { // Condition to check whether the element at i, is // greater than its next neighbouring element or not. if (i + 1 < n && arr[i] < arr[i + 1]) System.out.print(arr[i] + " "); else System.out.print(arr[i] + "\n"); } } // Driver code public static void main(String[] args) { int arr[] = { 9, 8, 11, 13, 10, 15, 14, 16, 20, 5 }; int n = arr.length; printmaxSubseq(arr, n); } } // This code is contributed by 29AjayKumar Python3 # Python3 Implementation to print all the # Maximal Increasing Sub-array of array # Function to print each of maximal # contiguous increasing subarray def printmaxSubseq(arr, n) : # Loop to iterate through the array and print # the maximal contiguous increasing subarray. for i in range(n - 1) : # Condition to check whether the element at i, is # greater than its next neighbouring element or not. if (arr[i] < arr[i + 1]) : print(arr[i], end = " "); else : print(arr[i]); print(arr[n - 1]); # Driver function if __name__ == "__main__" : arr = [ 9, 8, 11, 13, 10, 15, 14, 16, 20, 5 ]; n = len(arr); printmaxSubseq(arr, n); # This code is contributed by AnkitRai01 C# // C# Implementation to print all the // Maximal Increasing Sub-array of array using System; class GFG { // Function to print each of maximal // contiguous increasing subarray static void printmaxSubseq(int []arr, int n) { int i; // Loop to iterate through the array and print // the maximal contiguous increasing subarray. for (i = 0; i < n ; i++) { // Condition to check whether the element at i, is // greater than its next neighbouring element or not. if (i + 1 < n && arr[i] < arr[i + 1]) Console.Write(arr[i] + " "); else Console.WriteLine(arr[i]); } } // Driver code public static void Main() { int []arr = { 9, 8, 11, 13, 10, 15, 14, 16, 20, 5 }; int n = arr.Length; printmaxSubseq(arr, n); } } // This code is contributed by AnkitRai01 JavaScript <script> // Javascript Implementation to print all the // Maximal Increasing Sub-array of array // Function to print each of maximal // contiguous increasing subarray function printmaxSubseq(arr, n) { let i; // Loop to iterate through the array and print // the maximal contiguous increasing subarray. for (i = 0; i < n; i++) { // Condition to check whether the element at i, is // greater than its next neighbouring element or not. if (arr[i] < arr[i + 1]) document.write(arr[i] + " "); else document.write(arr[i] + "<br>"); } } // Driver function let arr = [ 9, 8, 11, 13, 10, 15, 14, 16, 20, 5 ]; let n = arr.length; printmaxSubseq(arr, n); </script> Output: 9 8 11 13 10 15 14 16 20 5 Time Complexity: O(n)Auxiliary Space: O(1), no extra space is required, so it is a constant. Comment More infoAdvertise with us Next Article Print all maximal increasing contiguous sub-array in an array E epistler_999 Follow Improve Article Tags : Mathematical Technical Scripter Competitive Programming Aptitude C++ Quiz DSA Arrays subarray +4 More Practice Tags : ArraysMathematical Similar Reads Maximize count of Decreasing Consecutive Subsequences from an Array Given an array arr[] consisting of N integers, the task is to find the maximum count of decreasing subsequences possible from an array that satisfies the following conditions: Each subsequence is in its longest possible form.The difference between adjacent elements of the subsequence is always 1. Ex 8 min read For each Array index find the maximum value among all M operations Given an array arr[] of size N initially filled with 0 and another array Positions[] of size M, the task is to return the maximum value for each index after performing the following M operations: Make the value at index Positions[i] equal to 0All the numbers to the right of Positions[i] will be one 6 min read Largest sum contiguous increasing subarray Given an array of n positive distinct integers. The problem is to find the largest sum of contiguous increasing subarray in O(n) time complexity. Examples : Input : arr[] = {2, 1, 4, 7, 3, 6}Output : 12Contiguous Increasing subarray {1, 4, 7} = 12Input : arr[] = {38, 7, 8, 10, 12}Output : 38Recommen 15 min read Maximum subarray sum in an array created after repeated concatenation | Set-2 Given an array arr[] consisting of N integers and a positive integer K, the task is to find the largest sum of any contiguous subarray in the modified array formed by repeating the given array K times. Examples: Input: arr[] = {-1, 10, 20}, K = 2Output: 59Explanation:After concatenating the array tw 15+ min read Maximum sum of increasing order elements from n arrays Given n arrays of size m each. Find the maximum sum obtained by selecting a number from each array such that the elements selected from the i-th array are more than the element selected from (i-1)-th array. If maximum sum cannot be obtained then return 0.Examples: Input : arr[][] = {{1, 7, 3, 4}, {4 13 min read Maximum absolute difference between sum of two contiguous sub-arrays Given an array of integers, find two non-overlapping contiguous sub-arrays such that the absolute difference between the sum of two sub-arrays is maximum. Example: Input: [-2, -3, 4, -1, -2, 1, 5, -3] Output: 12 Two subarrays are [-2, -3] and [4, -1, -2, 1, 5] Input: [2, -1, -2, 1, -4, 2, 8] Output: 15+ min read Maximum length of longest increasing contiguous subarray after deleting exactly one element from array Given an array arr[] of N integers. The task is to find the maximum length of the longest increasing contiguous subarray after removing exactly one element from the given array. Examples : Input : N = 5, arr[] = { 2, 4, 1, 5, 7 }Output : 4Explanation : After removing third element from the array, th 15+ min read K maximum sums of overlapping contiguous sub-arrays Given an array of Integers and an Integer value k, find out k sub-arrays(may be overlapping), which have k maximum sums. Examples: Input : arr = {4, -8, 9, -4, 1, -8, -1, 6}, k = 4 Output : 9 6 6 5Input : arr = {-2, -3, 4, -1, -2, 1, 5, -3}, k= 3 Output : 7 6 5 Using Kadane's Algorithm we can find t 13 min read Longest Increasing Subarray of Composite Numbers in Array Given an array of integers arr[], the task is to find the longest increasing subarray of composite numbers in an array. Examples: Input: arr[] = [1, 4, 7, 6, 8, 10, 12]Output: [6, 8, 10, 12]Explanation: The longest increasing subarray of composite numbers in the given array is [6, 8, 10, 12], which 12 min read Maximum sum increasing subsequence from a prefix and a given element after prefix is must Given an array of n positive integers, write a program to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i. Examples : Input: arr[] = {1, 101, 2, 3, 100, 4, 5} i-th index = 4 (Element at 4th index is 100 14 min read Like