VOOZH about

URL: https://www.geeksforgeeks.org/dsa/number-of-permutations-such-that-no-three-terms-forms-increasing-subsequence/

⇱ Number of Permutations such that no Three Terms forms Increasing Subsequence - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Number of Permutations such that no Three Terms forms Increasing Subsequence

Last Updated : 11 Jul, 2025

Given a number N. The task is to find the number of permutations of 1 to N such that no three terms of the permutation form an increasing subsequence.

Examples:  

Input : N = 3
Output : 5
Valid permutations : 132, 213, 231, 312 and 321 and not 123

Input : N = 4
Output : 14 

The above problem is an application of Catalan numbers. So, the task is to only find the nth Catalan Number. First few Catalan numbers are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, … (considered from 0th number)

Below is the program to find Nth Catalan Number:  


Output: 
5

 

Time Complexity: O(n)

Auxiliary Space: O(1)

Comment