title: Searching Array Adjacent Differ K
signature: searching_array_adjacent_differ_k <- function(arr, n, x, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, x, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, x, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 5L, 9L, 11L, 14L, 18L, 19L, 21L, 26L, 32L, 38L, 38L, 43L, 47L, 49L, 52L, 55L, 61L, 65L, 67L, 69L, 73L, 74L, 79L, 84L, 90L, 91L, 91L, 92L, 93L, 94L, 99L), 22L, 19L, 26L, 
          6L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(12L, -86L, -66L, -50L, -48L, 78L, -92L, -56L, -2L, 66L, 64L), 5L, 10L, 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 35L, 37L, 43L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(10L, 87L, 39L, 87L, 45L, 33L, 5L, 37L, 70L, 69L, 88L, 78L, 90L, 3L), 9L, 8L, 10L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-78L, -70L, -68L, -60L, -52L, -34L, -24L, -4L, 12L, 18L, 58L, 58L, 64L, 76L, 84L, 94L), 14L, 9L, 13L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L), 26L, 36L, 32L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(5L, 5L, 7L, 11L, 11L, 15L, 22L, 23L, 28L, 38L, 41L, 53L, 54L, 57L, 59L, 68L, 71L, 89L), 16L, 17L, 16L, 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-4L, 0L, 60L, -14L, -48L, 54L, -96L, -68L, -40L, 64L, -50L, -74L, -20L, -22L, 48L, -48L, 42L, 62L, 66L, 84L, 54L, -52L, -52L, 6L, 46L, -90L, -18L, 90L), 18L, 14L, 23L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L), 9L, 8L, 9L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(30L, 91L, 34L, 44L, 3L, 76L, 43L, 75L, 49L, 33L, 74L, 72L, 68L, 79L, 26L, 62L, 23L, 5L, 32L, 75L, 82L, 25L, 7L, 19L, 32L, 87L, 87L, 94L, 34L, 62L, 3L, 32L, 59L), 32L, 30L, 24L, 
          0L
      )))
  
  }
  
  main()
source_py: def searching_array_adjacent_differ_k(arr, n, x, k):
      i = 0
      while (i < n):
          if (arr[i] == x):
              return i
          i = (i + max(1, int((abs((arr[i] - x)) / k))))
      print('number is not present!')
      return (- 1)
source_cpp: int searching_array_adjacent_differ_k(vector<int> arr, int n, int x, int k) {
    int i = 0;
    while ( i < n ) {
      if ( arr [ i ] == x ) return i;
      i = i + max ( 1, abs ( arr [ i ] - x ) / k );
    }
    return - 1;
  }