Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Interview Questions on Array
  • Practice Array
  • MCQs on Array
  • Tutorial on Array
  • Types of Arrays
  • Array Operations
  • Subarrays, Subsequences, Subsets
  • Reverse Array
  • Static Vs Arrays
  • Array Vs Linked List
  • Array | Range Queries
  • Advantages & Disadvantages
Open In App
Next Article:
Minimize the number of strictly increasing subsequences in an array | Set 2
Next article icon

Minimize the number of strictly increasing subsequences in an array | Set 2

Last Updated : 26 Apr, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Given an array arr[] of size N, the task is to print the minimum possible count of strictly increasing subsequences present in the array. 
Note: It is possible to swap the pairs of array elements.

Examples:

Input: arr[] = {2, 1, 2, 1, 4, 3}
Output: 2
Explanation: Sorting the array modifies the array to arr[] = {1, 1, 2, 2, 3, 4}. Two possible increasing subsequences are {1, 2, 3} and {1, 2, 4}, which involves all the array elements.

Input: arr[] = {3, 3, 3}
Output: 3

MultiSet-based Approach: Refer to the previous post to solve the problem using Multiset to find the longest decreasing subsequence in the array. 
Time Complexity: O(N2)
Auxiliary Space: O(N)

Space-Optimized Approach: The optimal idea is based on the following observation:

Two elements with the same value can't be included in a single subsequence, as they won't form a strictly increasing subsequence. 
Therefore, for every distinct array element, count its frequency, say y. Therefore, at least y subsequences are required. 
Hence, the frequency of the most occurring array element is the required answer.

Follow the steps below to solve the problem:

  1. Initialize a variable, say count, to store the final count of strictly increasing subsequences.
  2. Traverse the array arr[] and perform the following observations: 
    • Initialize two variables, say X, to store the current array element, and freqX to store the frequency of the current array element.
    • Find and store all the occurrences of the current element in freqX.
    • If the frequency of the current element is greater than the previous count, then update the count.
  3. Print the value of count.

Below is the implementation of the above approach:

C++
// C++ program for // the above approach  #include <bits/stdc++.h> using namespace std;  // Function to find the number of strictly // increasing subsequences in an array int minimumIncreasingSubsequences(     int arr[], int N) {     // Sort the array     sort(arr, arr + N);      // Stores final count     // of subsequences     int count = 0;     int i = 0;      // Traverse the array     while (i < N) {          // Stores current element         int x = arr[i];          // Stores frequency of         // the current element         int freqX = 0;          // Count frequency of         // the current element         while (i < N && arr[i] == x) {             freqX++;             i++;         }          // If current element frequency         // is greater than count         count = max(count, freqX);     }      // Print the final count     cout << count; }  // Driver Code int main() {     // Given array     int arr[] = { 2, 1, 2, 1, 4, 3 };      // Size of the array     int N = sizeof(arr) / sizeof(arr[0]);      // Function call to find     // the number of strictly     // increasing subsequences     minimumIncreasingSubsequences(arr, N); } 
Java
// Java program to implement  // the above approach  import java.util.*; class GFG {    // Function to find the number of strictly // increasing subsequences in an array static void minimumIncreasingSubsequences(     int arr[], int N) {        // Sort the array     Arrays.sort(arr);      // Stores final count     // of subsequences     int count = 0;     int i = 0;      // Traverse the array     while (i < N)      {          // Stores current element         int x = arr[i];          // Stores frequency of         // the current element         int freqX = 0;          // Count frequency of         // the current element         while (i < N && arr[i] == x)          {             freqX++;             i++;         }          // If current element frequency         // is greater than count         count = Math.max(count, freqX);     }      // Print the final count     System.out.print(count); }  // Driver Code public static void main(String args[]) {     // Given array     int arr[] = { 2, 1, 2, 1, 4, 3 };      // Size of the array     int N = arr.length;      // Function call to find     // the number of strictly     // increasing subsequences     minimumIncreasingSubsequences(arr, N); } }  // This code is contributed by splevel62. 
Python3
# Python3 program to implement  # the above approach   # Function to find the number of strictly # increasing subsequences in an array def minimumIncreasingSubsequences(arr, N) :      # Sort the array     arr.sort()       # Stores final count     # of subsequences     count = 0     i = 0       # Traverse the array     while (i < N) :           # Stores current element         x = arr[i]           # Stores frequency of         # the current element         freqX = 0           # Count frequency of         # the current element         while (i < N and arr[i] == x) :             freqX += 1             i += 1           # If current element frequency         # is greater than count         count = max(count, freqX)       # Print the final count     print(count)  # Given array arr = [ 2, 1, 2, 1, 4, 3 ]  # Size of the array N = len(arr)  # Function call to find # the number of strictly # increasing subsequences minimumIncreasingSubsequences(arr, N)  # This code is contributed by divyesh072019. 
C#
// C# program to implement  // the above approach  using System;  public class GFG {    // Function to find the number of strictly // increasing subsequences in an array static void minimumIncreasingSubsequences(     int []arr, int N) {        // Sort the array     Array.Sort(arr);      // Stores readonly count     // of subsequences     int count = 0;     int i = 0;      // Traverse the array     while (i < N)      {          // Stores current element         int x = arr[i];          // Stores frequency of         // the current element         int freqX = 0;          // Count frequency of         // the current element         while (i < N && arr[i] == x)          {             freqX++;             i++;         }          // If current element frequency         // is greater than count         count = Math.Max(count, freqX);     }      // Print the readonly count     Console.Write(count); }  // Driver Code public static void Main(String []args) {        // Given array     int []arr = { 2, 1, 2, 1, 4, 3 };      // Size of the array     int N = arr.Length;      // Function call to find     // the number of strictly     // increasing subsequences     minimumIncreasingSubsequences(arr, N); } }  // This code is contributed by 29AjayKumar  
JavaScript
<script>     // Javascript program to implement the above approach          // Function to find the number of strictly     // increasing subsequences in an array     function minimumIncreasingSubsequences(arr, N)     {          // Sort the array         arr.sort(function(a, b){return a - b});          // Stores readonly count         // of subsequences         let count = 0;         let i = 0;          // Traverse the array         while (i < N)         {              // Stores current element             let x = arr[i];              // Stores frequency of             // the current element             let freqX = 0;              // Count frequency of             // the current element             while (i < N && arr[i] == x)             {                 freqX++;                 i++;             }              // If current element frequency             // is greater than count             count = Math.max(count, freqX);         }          // Print the readonly count         document.write(count);     }          // Given array     let arr = [ 2, 1, 2, 1, 4, 3 ];       // Size of the array     let N = arr.length;       // Function call to find     // the number of strictly     // increasing subsequences     minimumIncreasingSubsequences(arr, N);      // This code is contributed by suresh07. </script> 

 
 


Output: 
2

 

Time Complexity: O(NlogN)
Auxiliary Space: O(1) 


Next Article
Minimize the number of strictly increasing subsequences in an array | Set 2

S

shekabhi1208
Improve
Article Tags :
  • Sorting
  • Technical Scripter
  • DSA
  • Arrays
  • Technical Scripter 2020
  • subsequence
  • frequency-counting
Practice Tags :
  • Arrays
  • Sorting

Similar Reads

    Minimum number of strictly decreasing subsequences
    Given an array arr[] of size N. The task is to split the array into minimum number of strictly decreasing subsequences. Calculate the minimum number of subsequences we can get by splitting. Examples: Input: N = 4, arr[] = {3, 5, 1, 2}Output: 2Explanation: We can split the array into two subsequences
    7 min read
    Minimum number of increasing subsequences
    Given an array of integers of size N, you have to divide it into the minimum number of "strictly increasing subsequences" For example: let the sequence be {1, 3, 2, 4}, then the answer would be 2. In this case, the first increasing sequence would be {1, 3, 4} and the second would be {2}.Examples: In
    10 min read
    Maximize count of Decreasing Subsequences from the given Array
    Given an array arr[], the task is to rearrange the array to generate maximum decreasing subsequences and print the count of the maximum number of subsequences possible such that each array element can be part of a single subsequence and the length of the subsequences needs to be maximized. Example:
    5 min read
    Minimum number of elements which are not part of Increasing or decreasing subsequence in array
    Given an array of n elements. Make strictly increasing and strictly decreasing subsequences from the array such that each array element belongs to increasing subsequence or decreasing subsequence, but not both, or can be part of none of the subsequence. Minimize the number of elements which are not
    12 min read
    Count number of increasing subsequences of size k
    Given an array arr[] containing n integers. The problem is to count number of increasing subsequences in the array of size k. Examples: Input : arr[] = {2, 6, 4, 5, 7}, k = 3Output : 5The subsequences of size '3' are:{2, 6, 7}, {2, 4, 5}, {2, 4, 7},{2, 5, 7} and {4, 5, 7}.Input : arr[] = {12, 8, 11,
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences