title: Temple Offerings
signature: class Solution {
  
      public Integer templeOfferings(Integer n, ArrayList<Integer> templeheight) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, ArrayList<Integer> templeheight, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n, templeheight,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(12, new ArrayList<>(Arrays.asList(3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94)), 78);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(46, new ArrayList<>(Arrays.asList(76, 48, 88, 70, -64, 66, -6, -58, 26, -28, -42, -94, 80, -4, -56, -46, 4, 90, -12, -78, 64, 18, -38, 26, 56, -24, 66, -18, -12, 0, -94, 12, -10, 4, -68, -20, 88, 2, -58, 16, 46, -80, -42, 44, -86, 96, -44)), 92);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(16, new ArrayList<>(Arrays.asList(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)), 17);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(9, new ArrayList<>(Arrays.asList(2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7)), 15);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(0, new ArrayList<>(Arrays.asList(-88)), 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(38, new ArrayList<>(Arrays.asList(0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0)), 50);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(28, new ArrayList<>(Arrays.asList(2, 3, 6, 8, 9, 10, 14, 17, 17, 22, 25, 27, 29, 29, 30, 32, 33, 35, 38, 42, 50, 51, 51, 57, 59, 59, 59, 60, 62, 62, 63, 67, 70, 75, 76, 77, 81, 81, 83, 84)), 106);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(9, new ArrayList<>(Arrays.asList(-52, 62, 74, -62, -58, 62, 38, 42, -50, 20)), 16);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(18, new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 19);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(29, new ArrayList<>(Arrays.asList(96, 15, 9, 9, 40, 34, 17, 4, 51, 49, 34, 66, 97, 28, 64, 65, 92, 56, 74, 48, 43, 17, 82, 8, 21, 39, 83, 35, 42, 37, 64, 34, 42, 59, 45, 61, 55, 93, 94, 29, 20, 96, 77, 66)), 64);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, ArrayList<Integer> templeheight, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n, templeheight),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def temple_offerings(n, templeHeight):
      sum = 0
      for i in range(n):
          left = 0
          right = 0
          for j in range((i - 1), (- 1), (- 1)):
              if (templeHeight[j] < templeHeight[(j + 1)]):
                  left += 1
              else:
                  break
          for j in range((i + 1), n):
              if (templeHeight[j] < templeHeight[(j - 1)]):
                  right += 1
              else:
                  break
          sum += (max(right, left) + 1)
      return sum
source_cpp: int temple_offerings(int n, vector<int> templeHeight) {
    int sum = 0;
    for ( int i = 0;
    i < n;
    ++ i ) {
      int left = 0, right = 0;
      for ( int j = i - 1;
      j >= 0;
      -- j ) {
        if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left;
        else break;
      }
      for ( int j = i + 1;
      j < n;
      ++ j ) {
        if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right;
        else break;
      }
      sum += max ( right, left ) + 1;
    }
    return sum;
  }