title: How To Check If A Given Array Represents A Binary Heap 1
signature: how_to_check_if_a_given_array_represents_a_binary_heap_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 2L, 2L, 7L, 10L, 14L, 24L, 38L, 42L, 50L, 59L, 60L, 72L, 73L, 79L, 83L, 89L), 9L, 
          FALSE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-48L, 98L, 96L, -56L, -2L, 58L, 52L, -50L, 58L, 50L, 62L, 86L, -26L, -98L, 34L, 20L, -28L, 56L, -36L), 9L, 
          FALSE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 20L, 
          FALSE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(91L, 50L, 37L), 2L, 
          TRUE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-80L, -26L, 0L, 0L, 6L, 14L, 22L, 76L, 82L, 88L, 98L), 10L, 
          FALSE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L), 1L, 
          TRUE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L, 24L, 24L, 33L, 48L, 50L, 55L, 61L, 69L, 79L, 83L), 8L, 
          FALSE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(30L, 32L, -82L, -48L, 88L, -24L, 74L, 2L, 90L, 98L, 68L, 82L, 32L, -60L, 2L, -94L, 18L, 14L, 46L, 50L, -60L, -74L, -76L, 66L, -76L, -34L, -20L, 82L, -44L, -62L, 34L, 48L, -56L, 2L, 64L, -78L, -64L, 98L, -10L, -28L, 78L, -42L), 27L, 
          FALSE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 6L, 
          FALSE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(38L, 74L, 99L, 75L, 44L, 75L, 24L, 70L, 78L, 74L, 60L, 59L, 34L, 27L, 7L, 23L, 19L, 95L, 4L, 35L, 38L, 22L, 46L, 1L, 44L, 20L, 52L, 1L, 96L, 57L, 5L, 76L, 49L, 1L, 37L, 35L), 31L, 
          FALSE
      )))
  
  }
  
  main()
source_py: def how_to_check_if_a_given_array_represents_a_binary_heap_1(arr, n):
      for i in range((int(((n - 2) / 2)) + 1)):
          if (arr[((2 * i) + 1)] > arr[i]):
              return False
          if ((((2 * i) + 2) < n) and (arr[((2 * i) + 2)] > arr[i])):
              return False
      return True
source_cpp: bool how_to_check_if_a_given_array_represents_a_binary_heap_1(vector<int> arr, int n) {
    for ( int i = 0;
    i <= ( n - 2 ) / 2;
    i ++ ) {
      if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false;
      if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false;
    }
    return true;
  }