title: How To Check If A Given Array Represents A Binary Heap
signature: howToCheckIfAGivenArrayRepresentsABinaryHeap :: [Integer] -> Integer -> Integer -> Bool
  howToCheckIfAGivenArrayRepresentsABinaryHeap arr i 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 :: Bool -> Bool -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> Bool -> String
  driver arr i n expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr i n) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([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) )
  
      printf "TEST-1...%s\n" (driver ([-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) )
  
      printf "TEST-2...%s\n" (driver ([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) )
  
      printf "TEST-3...%s\n" (driver ([10, 2, 1, 34, 21, 37, 49, 31, 70, 97, 87, 50, 76, 55]) (0) (8) (False) )
  
      printf "TEST-4...%s\n" (driver ([-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) )
  
      printf "TEST-5...%s\n" (driver ([1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0]) (12) (11) (True) )
  
      printf "TEST-6...%s\n" (driver ([5, 20, 30, 5, 10, 21, 5]) (0) (7) (False) )
  
      printf "TEST-7...%s\n" (driver ([50, 20, 30, 5, 10, 21, 5]) (0) (7) (True) )
  
      printf "TEST-8...%s\n" (driver ([50, 20, 30, 5, 10, 21, 5]) (2) (7) (True) )
  
      printf "TEST-9...%s\n" (driver ([50, 20, 30, 5, 10, 21, 5]) (4) (7) (True) )
  
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;
  }