It’s not required to provide N because we can calculate it from string if needed. I think the sort implementation is out of scope of this question

Solution in Java

            
public String closestNumbers(String s) {
    String[] sNumbers = s.split(" ");
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < sNumbers.length; i++) {
        numbers.add(Integer.parseInt(sNumbers[i]));
    }

    java.util.Collections.sort(numbers);
    System.out.println(numbers.toString());

    int diff = 2147483647;
    String out = "";
    for (int i = 0; i < numbers.size() - 1; i++) {
        if (diff == (numbers.get(i + 1) - numbers.get(i))) {
            out = out + "\n" + numbers.get(i + 1) + " " + numbers.get(i);
        }
        if (diff > (numbers.get(i + 1) - numbers.get(i))) {
            diff = numbers.get(i + 1) - numbers.get(i);
            out = numbers.get(i + 1) + " " + numbers.get(i);
        }
    }
    return out;
}