title: Find The Element Before Which All The Elements Are Smaller Than It And After Which All Are Greater Than It
signature: findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt :: [Integer] -> Integer -> Integer
  findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt arr n = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> String
  driver arr n expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([4, 24, 30, 33, 56, 67, 87, 90]) (4) (3) )
  
      printf "TEST-1...%s\n" (driver ([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) )
  
      printf "TEST-2...%s\n" (driver ([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) )
  
      printf "TEST-3...%s\n" (driver ([51, 87, 46, 76, 2, 89, 56, 34, 49, 61, 44, 73, 14, 60, 89]) (11) (-1) )
  
      printf "TEST-4...%s\n" (driver ([-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) )
  
      printf "TEST-5...%s\n" (driver ([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) )
  
      printf "TEST-6...%s\n" (driver ([7, 8, 11, 12, 15, 17, 28, 34, 57, 61, 66, 76, 92]) (9) (8) )
  
      printf "TEST-7...%s\n" (driver ([-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) )
  
      printf "TEST-8...%s\n" (driver ([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) (9) (-1) )
  
      printf "TEST-9...%s\n" (driver ([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) )
  
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;
  }