title: Minimum Time To Finish Tasks Without Skipping Two Consecutive
signature: minimum_time_to_finish_tasks_without_skipping_two_consecutive <- 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(5L, 17L, 25L, 27L, 29L, 30L, 34L, 49L, 72L, 75L, 90L, 93L, 93L, 94L), 8L, 
          93L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-70L, -32L, 62L, 0L, -10L, 92L, -94L, -86L, 52L, 6L, -26L, -92L, -10L, 70L, -82L, 28L, 86L, 58L, 86L, -58L, 84L, -80L, -18L, -92L, -34L, 6L, 34L, 36L, 70L, -50L, -6L, -54L, 84L, 22L, 30L, -96L, -84L, 72L, 2L, 26L, -20L, 4L, 48L, -98L, 62L, -28L, -68L), 36L, 
          -834L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          5L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(34L, 40L, 92L, 35L, 29L, 26L, 12L, 66L, 7L, 28L, 86L, 4L, 35L, 79L, 1L, 48L, 41L, 47L, 15L, 75L, 45L, 6L, 3L, 94L, 39L, 50L, 20L, 8L, 58L, 51L, 83L, 44L, 53L, 76L, 19L, 84L, 68L, 54L, 36L, 53L), 29L, 
          359L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -98L, -92L, -92L, -88L, -82L, -74L, -70L, -68L, -68L, -64L, -60L, -52L, -52L, -42L, -42L, -38L, -36L, -36L, -34L, -26L, -24L, -22L, -12L, -2L, -2L, 4L, 6L, 44L, 44L, 48L, 54L, 62L, 62L, 64L, 74L, 78L, 82L, 86L, 86L, 90L, 90L, 94L), 36L, 
          -1152L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L), 5L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L, 15L, 19L, 29L, 30L, 39L, 40L, 61L), 4L, 
          28L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(92L, 0L, 46L, 70L, -60L, -50L, 58L, -56L, 8L, -90L, 84L, 16L, 40L, -62L, 50L, 78L, 26L, -42L, -40L, 98L, -52L, 62L, 16L, -62L, -76L, -70L, -60L, 32L, 4L, -68L, 52L, -64L, 70L, 12L, -10L), 21L, 
          -314L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L, 1L, 1L), 5L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(32L, 96L, 63L, 93L, 53L, 1L, 22L, 19L, 50L, 74L, 6L, 94L, 81L, 85L, 4L, 86L, 88L, 75L, 94L), 18L, 
          397L
      )))
  
  }
  
  main()
source_py: def minimum_time_to_finish_tasks_without_skipping_two_consecutive(arr, n):
      if (n <= 0):
          return 0
      incl = arr[0]
      excl = 0
      for i in range(1, n):
          incl_new = (arr[i] + min(excl, incl))
          excl_new = incl
          incl = incl_new
          excl = excl_new
      return min(incl, excl)
source_cpp: int minimum_time_to_finish_tasks_without_skipping_two_consecutive(vector<int> arr, int n) {
    if ( n <= 0 ) return 0;
    int incl = arr [ 0 ];
    int excl = 0;
    for ( int i = 1;
    i < n;
    i ++ ) {
      int incl_new = arr [ i ] + min ( excl, incl );
      int excl_new = incl;
      incl = incl_new;
      excl = excl_new;
    }
    return min ( incl, excl );
  }