> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/01-16-2022-1213.md).

# 01/16/2022 1213

using three pointers p1 p2 p3 point to each beginning of  arr1, arr2, arr3 and set them all = 0. While they are in the boundires: if arr1\[p1] == arr2\[p2] && arr2\[p2] == arr3\[p3], add this value into the list. else if arr1\[p1] < arr2\[p2], p1++, else if arr2\[p2] < arr3\[p3], p2++, then else p3++.

Time  O(N)

Space O(1)

class Solution {&#x20;

public List arraysIntersection(int\[] arr1, int\[] arr2, int\[] arr3) {&#x20;

List ans = new ArrayList <>(); // prepare three pointers to iterate through three arrays // p1, p2, and p3 point to the beginning of arr1, arr2, and arr3 accordingly i

nt p1 = 0, p2 = 0, p3 = 0;

```
    while (p1 < arr1.length && p2 < arr2.length && p3 < arr3.length) {

        if (arr1[p1] == arr2[p2] && arr2[p2] == arr3[p3]) {
            ans.add(arr1[p1]);
            p1++;
            p2++;
            p3++;
        } else {
            if (arr1[p1] < arr2[p2]) {
                p1++;
            } else if (arr2[p2] < arr3[p3]) {
                p2++;
            } else {
                p3++;
            }

        }
    }
    return ans;
}
```

}
