title: Search An Element In An Array Where Difference Between Adjacent Elements Is 1
signature: search_an_element_in_an_array_where_difference_between_adjacent_elements_is_1 <- function(arr, n, x) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, x, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(8L, 7L, 6L, 7L, 6L, 5L, 4L, 3L, 2L, 3L, 4L, 3L), 12L, 3L, 
          7L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(6L, 90L), 1L, 1L, 
          -1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(1L, 2L, 3L, 4L, 5L, 4L), 6L, 5L, 
          4L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(97L, 35L, 60L, 96L, 3L, 67L, 72L, 95L, 55L, 9L, 69L, 28L, 15L, 91L, 31L, 59L), 15L, 9L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-84L, -78L, -74L, -70L, -68L, -60L, -56L, -54L, -48L, -46L, -28L, -16L, -6L, 0L, 0L, 8L, 8L, 8L, 12L, 16L, 26L, 30L, 32L, 34L, 36L, 40L, 46L, 48L, 70L, 70L, 72L, 76L, 78L, 78L, 80L, 84L, 84L, 86L), 22L, 31L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L), 5L, 7L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(55L, 64L, 76L, 79L, 93L, 96L), 4L, 4L, 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(66L, -90L, 98L, -50L, 0L, 46L, 42L, 64L, -96L, -80L, -96L, 20L, -10L, -84L), 8L, 13L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L), 6L, 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(94L, 4L, 34L, 87L, 32L, 3L, 92L, 68L, 57L, 76L, 24L, 33L, 3L, 4L, 30L, 70L, 49L, 30L, 72L, 82L, 16L, 53L, 6L, 24L, 92L, 96L, 89L, 28L, 21L, 8L, 36L, 9L, 40L, 85L, 51L, 1L, 63L, 68L, 74L, 26L, 40L, 3L, 9L, 32L, 67L, 4L, 6L, 73L), 25L, 25L, 
          -1L
      )))
  
  }
  
  main()
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;
  }