title: Efficient Search In An Array Where Difference Between Adjacent Is 1
signature: fun efficientSearchInAnArrayWhereDifferenceBetweenAdjacentIs1(arr: ArrayList<Int>, n: Int, x: Int): Int {
source_py: def efficient_search_in_an_array_where_difference_between_adjacent_is_1(arr, n, x):
      i = 0
      while (i <= (n - 1)):
          if (arr[i] == x):
              return i
          i += abs((arr[i] - x))
      return (- 1)
source_cpp: int efficient_search_in_an_array_where_difference_between_adjacent_is_1(vector<int> arr, int n, int x) {
    int i = 0;
    while ( i <= n - 1 ) {
      if ( arr [ i ] == x ) return i;
      i += abs ( arr [ i ] - x );
    }
    return - 1;
  }
question_info.test_list: [{"idx": 0, "outputs": 3, "inputs": {"arr": [5, 4, 5, 6, 5, 4, 3, 2], "n": 29, "x": 6}}, {"idx": 1, "outputs": 6, "inputs": {"arr": [5, 4, 5, 6, 5, 4, 3, 2], "n": 19, "x": 3}}, {"idx": 2, "outputs": 14, "inputs": {"arr": [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 37, "x": 1}}, {"idx": 3, "outputs": 5, "inputs": {"arr": [50, 51, 52, 51, 50, 49, 48], "n": 17, "x": 49}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-86, -68, -32, -6, 6, 10, 30, 34, 58, 92], "n": 6, "x": 6}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0], "n": 27, "x": 22}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [58], "n": 0, "x": 0}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-64, 78, 58, 36, 48, 80, -80, 74, -98, 46, -48, 24, 80, 72, 90, -46, 14, 68, 38, 58, -54, 80, 44, -62, 34, -28, 92, 84, 90, 44, -26, 88, 18, 22, -32, 54, 58, 92], "n": 24, "x": 34}}, {"idx": 8, "outputs": 21, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1], "n": 35, "x": 1}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [5], "n": 0, "x": 0}}]
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(5, 4, 5, 6, 5, 4, 3, 2), 29, 6, 3)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(5, 4, 5, 6, 5, 4, 3, 2), 19, 3, 6)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 37, 1, 14)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(50, 51, 52, 51, 50, 49, 48), 17, 49, 5)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-86, -68, -32, -6, 6, 10, 30, 34, 58, 92), 6, 6, -1)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0), 27, 22, -1)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(58), 0, 0, -1)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-64, 78, 58, 36, 48, 80, -80, 74, -98, 46, -48, 24, 80, 72, 90, -46, 14, 68, 38, 58, -54, 80, 44, -62, 34, -28, 92, 84, 90, 44, -26, 88, 18, 22, -32, 54, 58, 92), 24, 34, -1)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1), 35, 1, 21)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(5), 0, 0, -1)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: efficientSearchInAnArrayWhereDifferenceBetweenAdjacentIs1
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