Input: arr[] = { 3, 4, 2, 1, 5 }
Output: 3
Explanation:
Possible pairs are { (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) }
Splitting the array into { 1, 2 } and { 3, 4, 5 }
Elements of each of the pairs { (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5) } are present into two different subsets.
Splitting the array into { 1, 3 } and { 2, 4, 5 }
Elements of each of the pairs { (1, 2), (1, 4), (1, 5), (2, 3), (3, 4), (3, 5) } are present into two different subsets.
Splitting the array into { 1, 3, 4 } and { 2, 5 }
Elements of each of the pairs { (1, 2), (1, 5), (2, 3), (3, 5), (2, 4), (4, 5) } are present into two different subsets.
Since elements of each pair of the array is present in two different subsets at least once, the required output is 3.
Input: arr[] = { 2, 1, 3 }
Output: 2