The following code snippet works only with duplicated numbers but I'm curious how to solve it with multiple repeated elements.
Input: 1, 2, 5, 5, 5, 8, 9, 11, 12, 1
Output: 1, 5
int[] arr = {1, 2, 5, 5, 5, 8, 9, 11, 12, 1};
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j] && i != j) {
System.out.print(arr[j] + " ");
}
}
}