title: Efficient Search In An Array Where Difference Between Adjacent Is 1
signature: def efficientSearchInAnArrayWhereDifferenceBetweenAdjacentIs1(arr: List[Int], n: Int, x: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(arr: List[Int], n: Int, x: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(5, 4, 5, 6, 5, 4, 3, 2), 29, 6, 
        3    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(5, 4, 5, 6, 5, 4, 3, 2), 19, 3, 
        6    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(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(s"TEST-3...${driver(
        List(50, 51, 52, 51, 50, 49, 48), 17, 49, 
        5    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-86, -68, -32, -6, 6, 10, 30, 34, 58, 92), 6, 6, 
        -1    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(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(s"TEST-6...${driver(
        List(58), 0, 0, 
        -1    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-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(s"TEST-8...${driver(
        List(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(s"TEST-9...${driver(
        List(5), 0, 0, 
        -1    
      )}")   
  
  }
  
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;
  }