Input: arr[] = { 1, 1, 2, 2, 5 }, K = 2
Output: 1
Explanation:
Replacing arr[4] with arr[0] modifies arr[] to { 1, 1, 2, 2, 1 }
Distinct array elements of the array arr[] are { 1, 2 }
Therefore, the required output is 1.
Input: arr[] = { 5, 1, 3, 2, 4, 1, 1, 2, 3, 4 }, K = 3
Output: 3
Explanation:
Replacing arr[0] with arr[1] modifies arr[] to { 1, 1, 3, 2, 4, 1, 1, 2, 3, 4 }
Replacing arr[2] with arr[0] modifies arr[] to { 1, 1, 1, 2, 4, 1, 1, 2, 3, 4 }
Replacing arr[8] with arr[0] modifies arr[] to { 1, 1, 1, 2, 4, 1, 1, 2, 1, 4 }
Distinct array elements of the array arr[] are { 1, 2, 4 }
Therefore, the required output is 3.