-
Notifications
You must be signed in to change notification settings - Fork 0
/
Make_Array_Elements_Unique.cpp
55 lines (45 loc) · 1.06 KB
/
Make_Array_Elements_Unique.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution {
public:
int minIncrements(vector<int>& arr) {
// Code here
long long int cnt = 0, maxi = 0;
sort(arr.begin(), arr.end());
for(int i = 1; i < arr.size(); i++)
{
if(arr[i] <= arr[i-1])
{
int val = arr[i-1] - arr[i]+1;
cnt += val;
arr[i] += val;
}
}
return cnt;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
cin.ignore();
while (t--) {
vector<int> a;
string input;
getline(cin, input);
stringstream ss(input);
int number;
while (ss >> number) {
a.push_back(number);
}
Solution ob;
int ans = ob.minIncrements(a);
cout << ans << endl;
cout << "~" << endl;
}
return 0;
}
// } Driver Code Ends