β Infinity Stones : Form Black Order - The Army of Thanos (Contest)
Infinity Stones : Form Black Order - The Army of Thanos easy Time Limit: 2 sec Memory Limit: 128000 kB
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i< arr.length ; i++){
arr[i] = sc.nextInt();
}
int count = 0;
for(int i = 0; i<n-2 ; i++){
for(int j = i+1; j<n-1 ; j++){
for(int k = j+1 ; k<n ;k++){
if((arr[i]<arr[j] && arr[j] < arr[k]) || (arr[i]>arr[j] && arr[j] > arr[k])){
count++;
}
}
}
}
System.out.print(count);
}
}
```
//method 02
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0; i<n;i++) arr[i]=sc.nextInt();
int count=0;
for(int i=0; i<n-2; i++){
for(int j=i+1; j<n-1; j++){
for(int k=j+1;k<n;k++){
if(arr[i]> arr[j] && arr[j]>arr[k]){
count++;
}else if(arr[i]<arr[j] && arr[j]<arr[k]){
count++;
}
}
}
}
System.out.println(count);
}
}
```Last updated