title: Find Subarray With Given Sum
signature: fun findSubarrayWithGivenSum(arr: ArrayList<Int>, n: Int, sum: Int): Int {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [4, 8, 8, 10, 15, 18, 19, 22, 25, 26, 30, 32, 35, 36, 40, 41, 43, 48, 53, 57, 59, 63, 64, 68, 71, 76, 76, 77, 78, 89, 96, 97], "n": 26, "sum": 23}}, {"idx": 1, "outputs": 0, "inputs": {"arr": [-78, 16, -16, -10, -2, -38, 58, -72, -78, 50, -68, -16, -96, 82, 70, 2, -20], "n": 9, "sum": 12}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], "n": 9, "sum": 11}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [16, 10, 55, 43, 46, 74, 57, 65, 86, 60, 28, 6, 92], "n": 10, "sum": 6}}, {"idx": 4, "outputs": 0, "inputs": {"arr": [-98, -98, -90, -84, -84, -80, -76, -76, -70, -54, -48, -46, -44, -42, -38, -14, -12, -4, 6, 8, 24, 28, 32, 40, 40, 42, 64, 84, 98], "n": 23, "sum": 19}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], "n": 12, "sum": 8}}, {"idx": 6, "outputs": 1, "inputs": {"arr": [2, 10, 40, 45, 56, 66, 66, 70, 75, 83, 93, 98], "n": 10, "sum": 10}}, {"idx": 7, "outputs": 0, "inputs": {"arr": [-20, 30, 56, -68, 54, -6, 78, -86, 88, -66, 76, -66, 62, 78, 22, 46, -94, -10, 18, 16, -36, 34, -98, -84, -40, 98, 82, 10, 12, 54, -88], "n": 30, "sum": 17}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 0, 1, 1], "n": 2, "sum": 2}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [38, 24, 12], "n": 1, "sum": 1}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, sum: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, sum), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(4, 8, 8, 10, 15, 18, 19, 22, 25, 26, 30, 32, 35, 36, 40, 41, 43, 48, 53, 57, 59, 63, 64, 68, 71, 76, 76, 77, 78, 89, 96, 97), 26, 23, 0)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-78, 16, -16, -10, -2, -38, 58, -72, -78, 50, -68, -16, -96, 82, 70, 2, -20), 9, 12, 0)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), 9, 11, 0)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(16, 10, 55, 43, 46, 74, 57, 65, 86, 60, 28, 6, 92), 10, 6, 0)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-98, -98, -90, -84, -84, -80, -76, -76, -70, -54, -48, -46, -44, -42, -38, -14, -12, -4, 6, 8, 24, 28, 32, 40, 40, 42, 64, 84, 98), 23, 19, 0)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1), 12, 8, 0)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(2, 10, 40, 45, 56, 66, 66, 70, 75, 83, 93, 98), 10, 10, 1)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-20, 30, 56, -68, 54, -6, 78, -86, 88, -66, 76, -66, 62, 78, 22, 46, -94, -10, 18, 16, -36, 34, -98, -84, -40, 98, 82, 10, 12, 54, -88), 30, 17, 0)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 1, 1), 2, 2, 0)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(38, 24, 12), 1, 1, 0)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: findSubarrayWithGivenSum
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn