


Solution of first question is :
import java.util.Scanner;
import java.util.Stack;
public class OaFirst {
public static int f(int a[] , int n){
if(n == 0 || n == 1) return n;
Stack <Integer> st = new Stack<>();
st.push(a[0]);
int count = 0;
for(int i = 1; i < n; i++){
int firstElement = a[i];
if(firstElement >= st.peek() ) st.push(firstElement);
else {
int temp = st.pop();
st.push(firstElement);
st.push(temp);
count++;
}
}
while(!st.isEmpty()){
int temp = st.pop();
if(st.size() != 0)
if(temp < st.peek() ) count++;
}
return count;
}
public static void main(String[] args) {
System.out.println("entet the size of an array");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("enter the element of an array");
int a[] = new int[n];
for(int i = 0; i < n; i++) a[i] = sc.nextInt();
System.out.println("ans is : " + f(a , n));
// 5
// 2 4 3 1 6
}
}


import java.util.HashSet;
import java.util.Scanner;
public class OaSecond {
public static int calculateVariability(String str, int n) {
if (n == 0 || n == 1) return n;
HashSet<String> uniqueStrings = new HashSet<>();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
StringBuilder sb = new StringBuilder(str);
String sub = sb.substring(i, j + 1);
StringBuilder reversedSub = new StringBuilder(sub).reverse();
sb.replace(i, j + 1, reversedSub.toString());
uniqueStrings.add(sb.toString());
}
}
return uniqueStrings.size();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int n = str.length();
int ans = calculateVariability(str, n);
System.out.println("answer is : " + ans);
}
}