package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

public class _986 {
    public static class Solution1 {
        public int[][] intervalIntersection(int[][] A, int[][] B) {
            int i = 0;
            int j = 0;
            List<int[]> list = new ArrayList<>();
            while (i < A.length && j < B.length) {
                int start = Math.max(A[i][0], B[j][0]);
                int end = Math.min(A[i][1], B[j][1]);
                if (start <= end) {
                    list.add(new int[]{start, end});
                }
                if (end == A[i][1]) {
                    i++;
                } else {
                    j++;
                }
            }
            int[][] result = new int[list.size()][2];
            for (int k = 0; k < list.size(); k++) {
                result[k] = list.get(k);
            }
            return result;
        }
    }
}

@@ -189,17 +189,25 @@
 int%5B%5D%5B%5D 
-A
+firstList
 , int%5B%5D%5B
@@ -208,17 +208,26 @@
 int%5B%5D%5B%5D 
-B
+secondList
 ) %7B%0A    
@@ -341,17 +341,25 @@
 le (i %3C 
-A
+firstList
 .length 
@@ -365,17 +365,26 @@
  && j %3C 
-B
+secondList
 .length)
@@ -427,18 +427,35 @@
 max(
-A%5Bi%5D%5B0%5D, B
+firstList%5Bi%5D%5B0%5D, secondList
 %5Bj%5D%5B
@@ -498,18 +498,35 @@
 min(
-A%5Bi%5D%5B1%5D, B
+firstList%5Bi%5D%5B1%5D, secondList
 %5Bj%5D%5B
@@ -664,17 +664,25 @@
 (end == 
-A
+firstList
 %5Bi%5D%5B1%5D) 
@@ -806,182 +806,52 @@
     
-int%5B%5D%5B%5D result = new int%5Blist.size()%5D%5B2%5D;%0A            for (int k = 0; k %3C list.size(); k++) %7B%0A                result%5Bk%5D = list.get(k);%0A            %7D%0A            return result
+return list.toArray(new int%5Blist.size()%5D%5B2%5D)
 ;%0A  

refactor 986