Count of Triplets – Decreasing Order

Count of Triplets – Decreasing Order: The program must accept N integers as the input. The program must print the count of triplets where the three integers are in strictly decreasing order among the given N integers as the output.
Note: The order of integers in the triplets must be in the same order as in the input.

Boundary Condition(s):
3 <= N <= 100
1 <= Each integer value <= 10^5

Input Format:
The first line contains N.
The second line contains N integers separated by a space.

Output Format:
The first line contains the count of triplets where the three integers are in strictly decreasing order among the given N integers.

Example Input/Output 1:
Input:
5
7 2 8 3 1

Output:
3

Explanation:
The 3 triplets are given below.
7 > 2 > 1
7 > 3 > 1
8 > 3 > 1

Example Input/Output 2:
Input:
9
75 82 23 44 81 91 72 24 92

Output:
8

N=int(input())
arr=list(map(int,input().split()))
count=0
for ind1 in range(0,N):
    for ind2 in range(ind1+1,N):
        for ind3 in range(ind2+1,N):
            if arr[ind1]>arr[ind2] and arr[ind2]>arr[ind3]:
                count+=1
print(count)

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.