title: Find Subarray With Given Sum
signature: find_subarray_with_given_sum <- function(arr, n, sum) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, sum, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, sum), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 8L, 8L, 10L, 15L, 18L, 19L, 22L, 25L, 26L, 30L, 32L, 35L, 36L, 40L, 41L, 43L, 48L, 53L, 57L, 59L, 63L, 64L, 68L, 71L, 76L, 76L, 77L, 78L, 89L, 96L, 97L), 26L, 23L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-78L, 16L, -16L, -10L, -2L, -38L, 58L, -72L, -78L, 50L, -68L, -16L, -96L, 82L, 70L, 2L, -20L), 9L, 12L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 9L, 11L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(16L, 10L, 55L, 43L, 46L, 74L, 57L, 65L, 86L, 60L, 28L, 6L, 92L), 10L, 6L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -98L, -90L, -84L, -84L, -80L, -76L, -76L, -70L, -54L, -48L, -46L, -44L, -42L, -38L, -14L, -12L, -4L, 6L, 8L, 24L, 28L, 32L, 40L, 40L, 42L, 64L, 84L, 98L), 23L, 19L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L), 12L, 8L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 10L, 40L, 45L, 56L, 66L, 66L, 70L, 75L, 83L, 93L, 98L), 10L, 10L, 
          1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-20L, 30L, 56L, -68L, 54L, -6L, 78L, -86L, 88L, -66L, 76L, -66L, 62L, 78L, 22L, 46L, -94L, -10L, 18L, 16L, -36L, 34L, -98L, -84L, -40L, 98L, 82L, 10L, 12L, 54L, -88L), 30L, 17L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L), 2L, 2L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(38L, 24L, 12L), 1L, 1L, 
          0L
      )))
  
  }
  
  main()
source_py: def find_subarray_with_given_sum(arr, n, sum):
      for i in range(n):
          curr_sum = arr[i]
          j = (i + 1)
          while (j <= n):
              if (curr_sum == sum):
                  print('Sum found between')
                  print(('indexes %d and %d' % (i, (j - 1))))
                  return 1
              if ((curr_sum > sum) or (j == n)):
                  break
              curr_sum = (curr_sum + arr[j])
              j += 1
      print('No subarray found')
      return 0
source_cpp: int find_subarray_with_given_sum(vector<int> arr, int n, int sum) {
    int curr_sum, i, j;
    for ( i = 0;
    i < n;
    i ++ ) {
      curr_sum = arr [ i ];
      for ( j = i + 1;
      j <= n;
      j ++ ) {
        if ( curr_sum == sum ) {
          return 1;
        }
        if ( curr_sum > sum || j == n ) break;
        curr_sum = curr_sum + arr [ j ];
      }
    }
    return 0;
  }