title: Search An Element In An Array Where Difference Between Adjacent Elements Is 1
signature: fun searchAnElementInAnArrayWhereDifferenceBetweenAdjacentElementsIs1(arr: ArrayList<Int>, n: Int, x: Int): Int {
source_py: def search_an_element_in_an_array_where_difference_between_adjacent_elements_is_1(arr, n, x):
      i = 0
      while (i < n):
          if (arr[i] == x):
              return i
          i = (i + abs((arr[i] - x)))
      print('number is not present!')
      return (- 1)
source_cpp: int search_an_element_in_an_array_where_difference_between_adjacent_elements_is_1(vector<int> arr, int n, int x) {
    int i = 0;
    while ( i < n ) {
      if ( arr [ i ] == x ) return i;
      i = i + abs ( arr [ i ] - x );
    }
    return - 1;
  }
question_info.test_list: [{"idx": 0, "outputs": 7, "inputs": {"arr": [8, 7, 6, 7, 6, 5, 4, 3, 2, 3, 4, 3], "n": 12, "x": 3}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [6, 90], "n": 1, "x": 1}}, {"idx": 2, "outputs": 4, "inputs": {"arr": [1, 2, 3, 4, 5, 4], "n": 6, "x": 5}}, {"idx": 3, "outputs": -1, "inputs": {"arr": [97, 35, 60, 96, 3, 67, 72, 95, 55, 9, 69, 28, 15, 91, 31, 59], "n": 15, "x": 9}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-84, -78, -74, -70, -68, -60, -56, -54, -48, -46, -28, -16, -6, 0, 0, 8, 8, 8, 12, 16, 26, 30, 32, 34, 36, 40, 46, 48, 70, 70, 72, 76, 78, 78, 80, 84, 84, 86], "n": 22, "x": 31}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1], "n": 5, "x": 7}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [55, 64, 76, 79, 93, 96], "n": 4, "x": 4}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [66, -90, 98, -50, 0, 46, 42, 64, -96, -80, -96, 20, -10, -84], "n": 8, "x": 13}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1], "n": 6, "x": 5}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [94, 4, 34, 87, 32, 3, 92, 68, 57, 76, 24, 33, 3, 4, 30, 70, 49, 30, 72, 82, 16, 53, 6, 24, 92, 96, 89, 28, 21, 8, 36, 9, 40, 85, 51, 1, 63, 68, 74, 26, 40, 3, 9, 32, 67, 4, 6, 73], "n": 25, "x": 25}}]
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, x: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(8, 7, 6, 7, 6, 5, 4, 3, 2, 3, 4, 3), 12, 3, 7)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(6, 90), 1, 1, -1)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(1, 2, 3, 4, 5, 4), 6, 5, 4)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(97, 35, 60, 96, 3, 67, 72, 95, 55, 9, 69, 28, 15, 91, 31, 59), 15, 9, -1)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-84, -78, -74, -70, -68, -60, -56, -54, -48, -46, -28, -16, -6, 0, 0, 8, 8, 8, 12, 16, 26, 30, 32, 34, 36, 40, 46, 48, 70, 70, 72, 76, 78, 78, 80, 84, 84, 86), 22, 31, -1)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1), 5, 7, -1)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(55, 64, 76, 79, 93, 96), 4, 4, -1)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(66, -90, 98, -50, 0, 46, 42, 64, -96, -80, -96, 20, -10, -84), 8, 13, -1)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 1), 6, 5, -1)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(94, 4, 34, 87, 32, 3, 92, 68, 57, 76, 24, 33, 3, 4, 30, 70, 49, 30, 72, 82, 16, 53, 6, 24, 92, 96, 89, 28, 21, 8, 36, 9, 40, 85, 51, 1, 63, 68, 74, 26, 40, 3, 9, 32, 67, 4, 6, 73), 25, 25, -1)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: searchAnElementInAnArrayWhereDifferenceBetweenAdjacentElementsIs1
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