1If the expected running time should be linear, you can't use a TreeSet, which sorts the input and therefore requires O(NlogN). Therefore you should use a HashSet, which requires O(N) time to add N elements.
2
3Besides, you don't need 4 loops. It's sufficient to add all the positive input elements to a HashSet (first loop) and then find the first positive integer not in that Set (second loop).
4
5int N = A.length;
6Set<Integer> set = new HashSet<>();
7for (int a : A) {
8 if (a > 0) {
9 set.add(a);
10 }
11}
12for (int i = 1; i <= N + 1; i++) {
13 if (!set.contains(i)) {
14 return i;
15 }
16}