title: Find The Element Before Which All The Elements Are Smaller Than It And After Which All Are Greater Than It
signature: class Solution {
  
      public Integer findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt(ArrayList<Integer> arr, Integer n) {
source_py: def find_the_element_before_which_all_the_elements_are_smaller_than_it_and_after_which_all_are_greater_than_it(arr, n):
      leftMax = ([None] * n)
      leftMax[0] = float('-inf')
      for i in range(1, n):
          leftMax[i] = max(leftMax[(i - 1)], arr[(i - 1)])
      rightMin = float('inf')
      for i in range((n - 1), (- 1), (- 1)):
          if ((leftMax[i] < arr[i]) and (rightMin > arr[i])):
              return i
          rightMin = min(rightMin, arr[i])
      return (- 1)
source_cpp: int find_the_element_before_which_all_the_elements_are_smaller_than_it_and_after_which_all_are_greater_than_it(vector<int> arr, int n) {
    int leftMax [ n ];
    leftMax [ 0 ] = INT_MIN;
    for ( int i = 1;
    i < n;
    i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ], arr [ i - 1 ] );
    int rightMin = INT_MAX;
    for ( int i = n - 1;
    i >= 0;
    i -- ) {
      if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i;
      rightMin = min ( rightMin, arr [ i ] );
    }
    return - 1;
  }
question_info.extension: java
question_info.entry_fn_name: findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 3, "inputs": {"arr": [4, 24, 30, 33, 56, 67, 87, 90], "n": 4}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [72, -48, 12, 4, 46, 36, 2, 58, 82, -88, -14, 56, 90, 76, 18, -6, -28, 18, 88, 90, 40, -68, -10, -82, -28, 16, 32, -90, 12, -86, -16, 78, -98, -52, -26, 80, 6, 50, 40, -12, 52, 38, -92, 94, -32, 14, -80, -88, 48], "n": 28}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 30}}, {"idx": 3, "outputs": -1, "inputs": {"arr": [51, 87, 46, 76, 2, 89, 56, 34, 49, 61, 44, 73, 14, 60, 89], "n": 11}}, {"idx": 4, "outputs": 28, "inputs": {"arr": [-90, -90, -80, -72, -68, -64, -62, -62, -60, -46, -44, -44, -44, -42, -42, -32, -22, -22, -18, -2, 4, 6, 10, 12, 14, 30, 34, 34, 40, 56, 56, 56, 58, 68, 74, 78, 78, 82, 84, 86, 88, 90, 92], "n": 29}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0], "n": 26}}, {"idx": 6, "outputs": 8, "inputs": {"arr": [7, 8, 11, 12, 15, 17, 28, 34, 57, 61, 66, 76, 92], "n": 9}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-22, -96, -78, -60, 34, -18, 86, -42, -78, 76, 8, 28, -80, 80, 6, -72, 34, 66, 84, 50, -4, 18, 72, -66, -68, -24, 56, -12, -70, 24, -82], "n": 19}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], "n": 9}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [79, 81, 55, 6, 78, 93, 81, 33, 29, 1, 27, 49, 21, 58, 22, 65, 44, 95, 6, 51, 75, 42, 14, 55, 79, 82, 90, 8, 15, 15, 53, 98, 76, 43, 33], "n": 30}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(4, 24, 30, 33, 56, 67, 87, 90)), 4, 3);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(72, -48, 12, 4, 46, 36, 2, 58, 82, -88, -14, 56, 90, 76, 18, -6, -28, 18, 88, 90, 40, -68, -10, -82, -28, 16, 32, -90, 12, -86, -16, 78, -98, -52, -26, 80, 6, 50, 40, -12, 52, 38, -92, 94, -32, 14, -80, -88, 48)), 28, -1);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 30, -1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(51, 87, 46, 76, 2, 89, 56, 34, 49, 61, 44, 73, 14, 60, 89)), 11, -1);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-90, -90, -80, -72, -68, -64, -62, -62, -60, -46, -44, -44, -44, -42, -42, -32, -22, -22, -18, -2, 4, 6, 10, 12, 14, 30, 34, 34, 40, 56, 56, 56, 58, 68, 74, 78, 78, 82, 84, 86, 88, 90, 92)), 29, 28);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0)), 26, -1);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(7, 8, 11, 12, 15, 17, 28, 34, 57, 61, 66, 76, 92)), 9, 8);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-22, -96, -78, -60, 34, -18, 86, -42, -78, 76, 8, 28, -80, 80, 6, -72, 34, 66, 84, 50, -4, 18, 72, -66, -68, -24, 56, -12, -70, 24, -82)), 19, -1);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1)), 9, -1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(79, 81, 55, 6, 78, 93, 81, 33, 29, 1, 27, 49, 21, 58, 22, 65, 44, 95, 6, 51, 75, 42, 14, 55, 79, 82, 90, 8, 15, 15, 53, 98, 76, 43, 33)), 30, -1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__