The Difference of 2 in Java
The challenge
The objective is to return all pairs of integers from a given array of integers that have a difference of 2.
The resulting array should be sorted in ascending order of values.
Assume there are no duplicate integers in the array. The order of the integers in the input array should not matter.
Examples:
The solution in Java code
Option 1:
|
|
Option 2:
|
|
Option 3:
|
|
Test cases to validate our solution
|
|