title: Linear pass over an array has me stumped
body: <p>Hi I'm trying to do a single linear pass over two arrays, here is my problem: I have it working with the commented code but it's not correct. I've tried to solve this problem for a whole night before asking for help - here is what I've tried:</p>
  
  <pre><code>////////////////////////////// PROBLEM STATEMENT //////////////////////////////
  // Given two arrays of ints sorted in increasing order, outer and inner,     //
  // print true if all of the numbers in inner appear in outer. The best       //
  // solution makes only a single "linear" pass of both arrays, taking         //
  // advantage of the fact that both arrays are already in sorted order.       //
  //   {1, 2, 4, 6}, {2, 4} -&gt; true                                            //
  //   {1, 2, 4, 6}, {2, 3, 4} -&gt; false                                        //
  //   {1, 2, 4, 4, 6}, {2, 4} -&gt; true                                         //
  ///////////////////////////////////////////////////////////////////////////////
  
    // &gt;&gt;&gt;&gt;&gt;&gt; Your Java Code Fragment starts here &lt;&lt;&lt;&lt;&lt;&lt;
    Boolean prez = true;
    Scanner kb = new Scanner(System.in);
    int n = kb.nextInt(); int z = 0;
    int[] inner = new int[n]; for(int i = 0; i &lt; inner.length; i++)inner[i] = kb.nextInt();
        n = kb.nextInt();
    int[] outer = new int[n]; for(int i = 0; i &lt; outer.length; i++)outer[i] = kb.nextInt();
  //   if(outer.length == 0)
  //     prez = true;   
  //  for(int i = 0; i &lt; outer.length; i++){
  //    for(int o = 0; o &lt; inner.length ; o++){
  //      if(outer[i] != inner[o]){
  //        prez = false;
  //      } if(outer[i] == inner[o]){
  //        prez = true;
  //        break;
  //      }
  //    }
  //    if(i == 1 &amp;&amp; outer[i] == 3){
  //       prez = false;
  //       break;
  //    }
  //  }
  //  for(z = 0; z &lt; outer.length ; z++){
  //    if(inner[z] == outer[z]){ 
  //      z++;
  //      prez = true;
  //    }else if(outer[z] != inner[z]){
  //      prez = false;
  //    }
  //  }
  
  
    int i = 0;
  //ok lodo so we loop through the array
  for(int j = 0; j &lt; inner.length; j++)
  {
  //while i is less than the outer length and out[i] is less than inner[j]??? 
      while(i &lt; outer.length &amp;&amp; outer[i] &lt; inner[j])
      {
      //we increase i 1
         i++;
      }
  // if "i" is the same or equal to outer size or the current outer doesnt equal inner make prez false 
      if(i &gt;= outer.length || outer[i] != inner[j])
      {
           prez = false;
  
      }
  }
  //prez = true;
  //print the results
  System.out.print(prez);
  </code></pre>
  
  <p>Am i understanding correctly? here is the output
  <img src="https://i.stack.imgur.com/G3Hh2.png" alt="enter image description here"></p>
  
  <p>I am trying lodo's solution as about. Here is the output
  Do i need a break when i get a false?</p>