title: How To Check If A Given Array Represents A Binary Heap
signature: class Solution {
  
      public Boolean howToCheckIfAGivenArrayRepresentsABinaryHeap(ArrayList<Integer> arr, Integer i, Integer n) {
source_py: def how_to_check_if_a_given_array_represents_a_binary_heap(arr, i, n):
      if (i > int(((n - 2) / 2))):
          return True
      if ((arr[i] >= arr[((2 * i) + 1)]) and (arr[i] >= arr[((2 * i) + 2)]) and how_to_check_if_a_given_array_represents_a_binary_heap(arr, ((2 * i) + 1), n) and how_to_check_if_a_given_array_represents_a_binary_heap(arr, ((2 * i) + 2), n)):
          return True
      return False
source_cpp: bool how_to_check_if_a_given_array_represents_a_binary_heap(vector<int> arr, int i, int n) {
    if ( i > ( n - 2 ) / 2 ) return true;
    if ( arr [ i ] >= arr [ 2 * i + 1 ] && arr [ i ] >= arr [ 2 * i + 2 ] && how_to_check_if_a_given_array_represents_a_binary_heap ( arr, 2 * i + 1, n ) && how_to_check_if_a_given_array_represents_a_binary_heap ( arr, 2 * i + 2, n ) ) return true;
    return false;
  }
question_info.extension: java
question_info.entry_fn_name: howToCheckIfAGivenArrayRepresentsABinaryHeap
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"arr": [1, 2, 3, 5, 24, 24, 25, 25, 36, 37, 37, 39, 42, 44, 46, 50, 51, 54, 56, 60, 62, 70, 71, 73, 75, 80, 80, 85, 86, 89, 91, 95, 99], "i": 0, "n": 18}}, {"idx": 1, "outputs": false, "inputs": {"arr": [-44, -58, 88, -42, 42, -14, -44, 42, 64, 94, -46, -70, 34, -10, -46, -52, -6, -78, 64, 56, 74, 98, -34, -4, -92, 6, -52, -20, 78, -72, -40], "i": 0, "n": 27}}, {"idx": 2, "outputs": false, "inputs": {"arr": [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, 1], "i": 0, "n": 20}}, {"idx": 3, "outputs": false, "inputs": {"arr": [10, 2, 1, 34, 21, 37, 49, 31, 70, 97, 87, 50, 76, 55], "i": 0, "n": 8}}, {"idx": 4, "outputs": false, "inputs": {"arr": [-94, -84, -82, -66, -64, -62, -56, -38, -24, -24, -4, 2, 4, 4, 8, 14, 16, 20, 30, 34, 34, 48, 58, 58, 70, 76, 78, 86, 88, 96, 98], "i": 0, "n": 26}}, {"idx": 5, "outputs": true, "inputs": {"arr": [1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0], "i": 12, "n": 11}}, {"idx": 6, "outputs": false, "inputs": {"arr": [5, 20, 30, 5, 10, 21, 5], "i": 0, "n": 7}}, {"idx": 7, "outputs": true, "inputs": {"arr": [50, 20, 30, 5, 10, 21, 5], "i": 0, "n": 7}}, {"idx": 8, "outputs": true, "inputs": {"arr": [50, 20, 30, 5, 10, 21, 5], "i": 2, "n": 7}}, {"idx": 9, "outputs": true, "inputs": {"arr": [50, 20, 30, 5, 10, 21, 5], "i": 4, "n": 7}}]
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 i, Integer n, Boolean expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, i, 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(1, 2, 3, 5, 24, 24, 25, 25, 36, 37, 37, 39, 42, 44, 46, 50, 51, 54, 56, 60, 62, 70, 71, 73, 75, 80, 80, 85, 86, 89, 91, 95, 99)), 0, 18, false);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-44, -58, 88, -42, 42, -14, -44, 42, 64, 94, -46, -70, 34, -10, -46, -52, -6, -78, 64, 56, 74, 98, -34, -4, -92, 6, -52, -20, 78, -72, -40)), 0, 27, false);
          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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 0, 20, false);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(10, 2, 1, 34, 21, 37, 49, 31, 70, 97, 87, 50, 76, 55)), 0, 8, false);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-94, -84, -82, -66, -64, -62, -56, -38, -24, -24, -4, 2, 4, 4, 8, 14, 16, 20, 30, 34, 34, 48, 58, 58, 70, 76, 78, 86, 88, 96, 98)), 0, 26, false);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0)), 12, 11, true);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(5, 20, 30, 5, 10, 21, 5)), 0, 7, false);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(50, 20, 30, 5, 10, 21, 5)), 0, 7, true);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(50, 20, 30, 5, 10, 21, 5)), 2, 7, true);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(50, 20, 30, 5, 10, 21, 5)), 4, 7, true);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer i, Integer n, Boolean expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, i, n),expected);
      }
      
      public boolean validateSolution(Boolean actual, Boolean 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__