-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ22.cpp
More file actions
36 lines (32 loc) · 806 Bytes
/
Copy pathQ22.cpp
File metadata and controls
36 lines (32 loc) · 806 Bytes
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
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<string> want, vector<int> number, vector<string> discount) {
int answer = 0;
map<string, int> count;
for (int i = 0; i < 10; i++) {
count[discount[i]] += 1;
}
int left = 0;
int right = 9;
while (right < discount.size()) {
bool valid = true;
for (int i = 0; i < want.size(); i++) {
if (count[want[i]] != number[i]) {
valid = false;
break;
}
}
if (valid) {
answer++;
}
right++;
if (right >= discount.size()) {
break;
}
count[discount[right]] += 1;
count[discount[left++]] -= 1;
}
return answer;
}