title: Twin array Find a Minimum value from each Array index must be different
body: <p>You are given two arrays A  and B each containing n, integers. You need to choose exactly  one number from A and exactly one number from B such that the index of the two chosen numbers is not same and the sum of the 2 chosen values is minimum.</p>
  
  <p>Your objective is to find and print this minimum value.</p>
  
  <p>For example in the image shown below  is the minimum sum.
  <a href="https://i.stack.imgur.com/VCQal.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VCQal.jpg" alt="enter image description here"></a></p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  import java.text.*;
  import java.math.*;
  import java.util.regex.*;
  
  public class Solution {
  
      static int twinArrays(int[] ar1, int[] ar2){
          // Complete this function
          int minAr1 = ar1[0];
          int minAr2;
          int index = 0;
          for(int i =0; i&lt;ar1.length;i++) {
              if(ar1[i]&lt;minAr1) {
                  minAr1 = ar1[i];
                  index = i;
              }
          }
          if(index == 0) {
              minAr2 = ar2[1];
          }else {
              minAr2 =ar2[0];
          }
  
          for(int j=0;j&lt;ar2.length;j++) {
              if(j!=index &amp;&amp; minAr2&gt;ar2[j]) {
                  minAr2 =ar2[j];
              }
          }
          return minAr1+minAr2;
       }
  
      public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
          int n = in.nextInt();
          if(n&gt;=2 &amp;&amp; n&lt;=1000000) {
          int[] ar1 = new int[n];
          for(int ar1_i = 0; ar1_i &lt; n; ar1_i++){
              int temp1 = in.nextInt();
              if(temp1&gt;=1&amp;&amp;temp1&lt;=1000000) {
                  ar1[ar1_i] = temp1;
              }
          }
          int[] ar2 = new int[n];
          for(int ar2_i = 0; ar2_i &lt; n; ar2_i++){
              int temp2 = in.nextInt();
              if(temp2&gt;=1&amp;&amp;temp2&lt;=1000000) {
                  ar2[ar2_i] = temp2;
              }
          }
          int result = twinArrays(ar1, ar2);
          System.out.println(result);
          }
  
      }
  }
  </code></pre>
  
  <p>i have Implemented that is working fine but still something is missing so some test case failing could anyone give me some clue and hint to optimize my code if you find any defect in this code </p>