title: Find The Minimum Distance Between Two Numbers 1
signature: class Solution {
  
      public Integer findTheMinimumDistanceBetweenTwoNumbers1(ArrayList<Integer> arr, Integer n, Integer x, Integer y) {
source_py: def find_the_minimum_distance_between_two_numbers_1(arr, n, x, y):
      min_dist = sys.maxsize
      for i in range(n):
          if ((arr[i] == x) or (arr[i] == y)):
              prev = i
              break
      while (i < n):
          if ((arr[i] == x) or (arr[i] == y)):
              if ((arr[prev] != arr[i]) and ((i - prev) < min_dist)):
                  min_dist = (i - prev)
                  prev = i
              else:
                  prev = i
          i += 1
      return min_dist
source_cpp: int find_the_minimum_distance_between_two_numbers_1(vector<int> arr, int n, int x, int y) {
    int i = 0;
    int min_dist = INT_MAX;
    int prev;
    for ( i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] == x || arr [ i ] == y ) {
        prev = i;
        break;
      }
    }
    for (;
    i < n;
    i ++ ) {
      if ( arr [ i ] == x || arr [ i ] == y ) {
        if ( arr [ prev ] != arr [ i ] && ( i - prev ) < min_dist ) {
          min_dist = i - prev;
          prev = i;
        }
        else prev = i;
      }
    }
    return min_dist;
  }
question_info.extension: java
question_info.entry_fn_name: findTheMinimumDistanceBetweenTwoNumbers1
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 11, "inputs": {"arr": [4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92], "n": 22, "x": 7, "y": 40}}, {"idx": 1, "outputs": 4, "inputs": {"arr": [96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16], "n": 25, "x": 58, "y": 70}}, {"idx": 2, "outputs": 12, "inputs": {"arr": [46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90], "n": 26, "x": 54, "y": 82}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98], "n": 24, "x": 0, "y": 4}}, {"idx": 4, "outputs": 1, "inputs": {"arr": [0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1], "n": 10, "x": 0, "y": 1}}, {"idx": 5, "outputs": 18, "inputs": {"arr": [1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93], "n": 27, "x": 1, "y": 42}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer x, Integer y, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n, x, y,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92)), 22, 7, 40, 11);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16)), 25, 58, 70, 4);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90)), 26, 54, 82, 12);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98)), 24, 0, 4, 1);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1)), 10, 0, 1, 1);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93)), 27, 1, 42, 18);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer x, Integer y, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n, x, y),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5
question_info.commands: java __FILENAME__