Skip to content

Commit 180a565

Browse files
authored
Create 2300. Successful Pairs of Spells and Potions 2 Apr
2300. Successful Pairs of Spells and Potions
1 parent dde993a commit 180a565

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
4+
int postfix[100001] = {0};
5+
for(auto potion: potions) postfix[potion]++;
6+
for(int i=99999; i>=0; --i) postfix[i] += postfix[i+1];
7+
8+
//No need extra space at all for storing final result
9+
for(int i=0; i<spells.size(); ++i){
10+
long long val = success / (long long) spells[i];
11+
if(success % (long long) spells[i] != 0) val++;
12+
13+
spells[i] = val <= 1e5 ? postfix[val] : 0;
14+
}
15+
return spells;
16+
}
17+
};

0 commit comments

Comments
 (0)