Find The Duplicates in two arrays Find The Duplicates

Given two sorted arrays arr1 and arr2 of passport numbers, implement a function findDuplicates that returns an array of all passport numbers that are both in arr1 and arr2. Note that the output array should be sorted in an ascending order.

Let N and M be the lengths of arr1 and arr2, respectively. Solve for two cases and analyze the time &amp; space complexities of your solutions: M ≈ N - the array lengths are approximately the same M ≫ N - arr2 is much bigger than arr1.

My approach:

import java.io.*;
import java.util.*;
import java.lang.*;

class Solution {

  static int[] findDuplicates(int[] arr1, int[] arr2) {
    // your code goes here
    int i = 0, j = 0, k = 0;
    ArrayList&lt;Integer&gt; ans = new ArrayList&lt;&gt;();
    while(( i &lt; arr1.length) &amp;&amp; (j &lt; arr2.length))
    {
      if(arr1[i] &lt; arr2[j])
          i++;
      else if(arr1[i] == arr2[j])
      {
          ans.add(arr1[i]);
          k++;
          i++;
          j++;
      }
      else
          j++;
     }
    int[] arr = new int[ans.size()];

    for(int l = 0; l &lt; ans.size(); l++) {
    if (ans.get(l) != null) {
        arr[l] = ans.get(l);
    }
}
    return arr;
  }
   //M = arr1.length, N = arr2.length        
  //Time = O(M+N)
  //Space = O(min(M,N))


I have the following questions regarding my code:

1) How can I improve the time and space complexity of my code?

2) Is there a better way(lesser lines of code, better data structures) that can be used to improve the code?

Source: Mock interview
Here are my comments:


The variable k was probably meant to keep track of size of the array list (number of duplicates).  However, it is redundant, since you use the list's size() method. 
To convert a list to array you can use the stream API. while I am not certain if it provides any time/space benefits, it is probably the most optimized way to do it, and it saves you having to declare the return array. Since it is tricky to do the conversion with primitive types arrays, here it is: ans.stream().mapToInt(item -&gt; item.intValue()).toArray(); and you can make it the return value of the method.
The while condition is using redundant parentheses that have the &amp;&amp; between them . It can be argued as a matter of taste, but in my eyes, the condition is clearer without them. I add an additional space around the higher order operator: while(i &lt; arr1.length  &amp;&amp;  j &lt; arr2.length)