import java.util.*;

public class Solution {
    public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
        ArrayList<Integer> list = new ArrayList<>();

        if(array == null || array.length == 0){
            return list;
        }

        int i = 0, j = array.length - 1;

        while(i < j){
            int k = array[i] + array[j];
            if(k == sum){
                list.addAll(Arrays.asList(array[i],array[j]));
                return list;
            }else if(k > sum){
                j--;
            }else{
                i++;
            }
        }

        return list;
    }
}