-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
68 lines (59 loc) · 1.23 KB
/
hash.cpp
File metadata and controls
68 lines (59 loc) · 1.23 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
// number hashing;
//int main() {
// int n;
// cin >> n;
// int arr[n];
// for (int i = 0; i < n; i++) {
// cin >> arr[i];
// }
// int hash[13] = {0};
// for (int i = 0; i < n; i++) {
// hash[arr[i]]++;
// }
// int q;
// cin >> q;
// while (q--) {
// int c;
// cin >> c;
// cout << hash[c] << endl;
// }
//
// return 0;
//}
// string hashing
int maxFrequency(vector<int> &nums, int k) {
sort(nums.begin(), nums.end());
long maxFreq = 0;
long left = 0;
long long sum = 0;
for (int right = 0; right < nums.size(); ++right) {
sum += nums[right];
while (nums[right] * (right - left + 1) - sum > k) {
sum -= nums[left];
left++;
}
maxFreq = max(maxFreq, right - left + 1);
}
return maxFreq;
}
int main() {
string s = "aabaaaacaabc";
// cin >> s;
int hash[26] = {0};
for (int i = 0; i < s.size(); i++) {
hash[s[i] - 'a']++;
}
for (auto i: hash) {
cout << i << " ";
}
// int t;
// cin >> t;
// while (t--) {
// char ch;
// cin >> ch;
// cout << hash[ch - 'a'];
// }
return 0;
}